I am creating a document from an Excel spreadsheet. All of that works fine. However, I need to format different lines differently. Whenever I run the code, it changes the format of everything in the document to whatever I set the current font to be. I have pasted a test example below. What am I missing?
Thanks for any help!
Sub CreateNewWordDoc()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim DirectoryName As String
DirectoryName = "C:\Temp\"
Set wrdApp = New Word.Application
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add
With wrdDoc
.Content.InsertAfter ("Font Should Be 18")
.Content.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Content.Font.Size = 18
.Content.Font.Bold = wdToggle
.Content.InsertParagraphAfter
.Content.InsertAfter ("Font Should Be 11")
.Content.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Content.Font.Size = 11
.Content.Font.Bold = wdToggle
.Content.InsertParagraphAfter
.SaveAs (DirectoryName & "Test.doc")
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub
Reply via web post | Reply to sender | Reply to group | Start a New Topic | Messages in this topic (1) |
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.
----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA
----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com
----------------------------------
Tidak ada komentar:
Posting Komentar