Using Excel VBA to Format Word Document

T

Tom K

Here is the code that I have. What I can't get to work is the
section where I am trying to change the Font Name & Font Size.
I run this macro from Excel (with the eventual goal being to have it
run on multiple files). Everything else seems to work right; but the
Font refuses to change.

Any help would be appreciated!

Dim wdApp As Word.Application, wdDoc As Word.Document
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0

Set wdDoc = wdApp.Documents.Open("c:\myfile.txt")

wdApp.Visible = True

wdApp.Activate

wdDoc.Select
'''''''' BEGINNING OF FONT CODE
With ActiveDocument.Styles(wdStyleNormal).Font
..Size = 7
..Name = "Arial"
End With
'''''' END OF FONT CODE
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientLandscape
.TopMargin = InchesToPoints(0.2)
.BottomMargin = InchesToPoints(0.2)
.LeftMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(11)
.PageHeight = InchesToPoints(8.5)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With

wdDoc.SaveAs "c:\myfile.doc"
wdDoc.Activate
'etc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top