Reputation: 2527
I am able to write to Word Document from a VBA macro, but I am having trouble with syntax to generate headers, paragraphs, tables etc...
This example writes two lines to a Word Document, but both come out as header style. I would like one line header and one line in paragraph or "normal" style...
Dim wdApp As Word.Application
Set wdApp = New Word.Application
With wdApp
.Visible = True
.Activate
.Documents.Add
With .Selection
.Style = "Heading 1"
.TypeText ("My Heading")
.TypeParagraph
.Style = "Normal"
.TypeText ("Some regular paragraph text")
End With
Upvotes: 1
Views: 2353
Reputation: 2527
This does what I want.
With .Selection
.Style = "Heading 1"
.TypeText "Header 1"
.TypeParagraph
.Style = "Heading 2"
.TypeText "Header 1.1"
.TypeParagraph
.Style = "No Spacing"
.TypeText "some text"
.TypeParagraph
.Style = "Heading 1"
.TypeText "Header 2"
.TypeParagraph
End With
Upvotes: 0