BaseBallBatBoy
New Member
- Joined
- Sep 12, 2011
- Messages
- 24
Hi,
So far I filled a txt file out of Excel 2007 VBA. Now I would like to push the same text into a word file. Just the text itself works fine, but now comes formatting, which I don't really understand how it works. Here is what I've done so far:
Now, how can I apply a certain style to a text I just inserted before? I believe it's self-explanatory out of my code which text needs to have which style.
Regards,
BBBB
So far I filled a txt file out of Excel 2007 VBA. Now I would like to push the same text into a word file. Just the text itself works fine, but now comes formatting, which I don't really understand how it works. Here is what I've done so far:
Code:
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Add ' create a new document
With wrdDoc
.Styles(wdStyleHeading1).Font.Name = "Arial"
.Styles(wdStyleHeading1).Font.Size = 16
.Styles(wdStyleHeading1).Font.Bold = True
.Styles(wdStyleHeading1).Font.Color = wdColorBlack
.Styles(wdStyleHeading2).Font.Name = "Arial"
.Styles(wdStyleHeading2).Font.Size = 12
.Styles(wdStyleHeading2).Font.Bold = True
.Styles(wdStyleHeading2).Font.Color = wdColorBlack
.Styles(wdStyleNormal).Font.Name = "Arial"
.Styles(wdStyleNormal).Font.Size = 10
.Styles(wdStyleNormal).Font.Color = wdColorBlack
.Content.ParagraphFormat.LineSpacingRule = wdLineSpaceExactly
.Content.ParagraphFormat.LineSpacing = 10
.Content.InsertAfter "THIS SHOULD BE HEADING1"
.Content.InsertParagraphAfter
.Content.InsertAfter "THIS SHOULD BE HEADING2"
.Content.InsertParagraphAfter
.Content.InsertAfter "THIS SHOULD BE NORMAL"
.Content.InsertParagraphAfter
.SaveAs (path)
.Close ' close the document
End With ' With wrdDoc
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
Now, how can I apply a certain style to a text I just inserted before? I believe it's self-explanatory out of my code which text needs to have which style.
Regards,
BBBB