I am trying to format a Word Document from an Excel Document. I am getting
Runtime Error 5941: The requested member of the collection does not exist.
I am simply trying to style the second paragraph as the Normal built in style. My lack of experience probably shows. The problem seems to be with the paragraph selection, but I'm not entirely sure how to go about it.
Dim WordApp As Word.Application
Set WordApp = New Word.Application
WordApp.Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0
WordApp.Visible = True
WordApp.Selection.TypeText ("New Document")
WordApp.Selection.Paragraphs(1).Style = wdStyleHeading1
WordApp.Selection.TypeText vbNewLine & "Date" & Date
WordApp.Selection.Paragraphs(2).Style = wdStyleNormal
End Sub
Edit: I am now trying to find the best way to change format on the same line. For Example:
Date: 10/02/2021
The problem is that so far my style changes apply to a whole paragraph. Any ideas?
WordApp.ActiveDocument.Paragraphs(2).Style = wdStyleNormalinstead? - braXActiveDocumentmay work it is bad practice for a whole host of reasons. Best practice is to use a variable as demonstrated in the answer from macropod, i.e.Set WdDoc = .Documents.Add. - Timothy Rylatt