In researching over and over, maybe I should use a range to mark each section of text, and then change that range to whatever formatting needed.
From: ExcelVBA@yahoogroups.com [mailto:ExcelVBA@yahoogroups.com] On Behalf Of twlewis64
Sent: Wednesday, February 13, 2013 2:09 PM
To: ExcelVBA@yahoogroups.com
Subject: [ExcelVBA] Formatting Word document from Excel VBA
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
[Non-text portions of this message have been removed]
Reply via web post | Reply to sender | Reply to group | Start a New Topic | Messages in this topic (2) |
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