Unable to view automated Word document

jbotts

Registered User.
Local time
Today, 03:54
Joined
Jun 8, 2009
Messages
22
Using the following code the Word document does not appear on top but rather shows up in the task tray. I have tried inserting DoEvents as well as .Activate and nothing seems to work. Here is the code:

Dim objWD2 As Word.Application
Dim oDoc As Word.Document
Dim oSec As Word.Section

Set objWD2 = CreateObject("Word.Application")
Set oDoc = objWD2.Documents.Open(path)
Set oSec = oDoc.Sections(1)

oSec.Headers(wdHeaderFooterPrimary).Range.Text = oDoc.Name
oSec.Headers(wdHeaderFooterPrimary).PageNumbers.Add.Alignment =
wdAlignPageNumberRight
oSec.Headers(wdHeaderFooterPrimary).PageNumbers.NumberStyle = wdPageNumberStyleNumberInDash

objWD2.ActiveDocument.PageSetup.Orientation = wdOrientLandscape
objWD2.ActiveDocument.Tables(1).AutoFitBehavior (wdAutoFitWindow)
objWD2.ActiveDocument.SaveAs FileName:=path

objWD2.Application.WindowState = wdWindowStateMaximize
objWD2.Visible = True

Any suggestions would be appreciated
 

Users who are viewing this thread

Back
Top Bottom