PDA

View Full Version : Open word from excel help



SilverSN95
07-29-2009, 09:26 AM
Hi,
I am writing a macro in excel that opens a word template and fills in certain data that is stored in the original excel workbook. Stepping though the code, I've noticed that the first time I call documents.open(), the macro pauses momentarily but the word file does not display, and the rest of the macro runs fine. The second time I run it, at documents.open() the word file does display and has the data entered twice - indicating to me that it was open the first time just not displayed.
I'm guessing its just something simple I missed, but this is my first time doing this so if someone can show me where I went wrong I'd appreciate it.
Public Sub FillEduTemplate()
Dim wdApp As Word.Application
Application.ScreenUpdating = False
Dim sourceWB As Workbook
Dim dest As Word.Document

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0

Set sourceWB = ThisWorkbook
Set sourceWS = sourceWB.Sheets("Express Profile")

Set dest = wdApp.Documents.Open("X:\*****")

With sourceWS
More code....
Thanks

SilverSN95
07-29-2009, 10:59 AM
It looks like I just needed to add
wdApp.Visible = True
dest.Activate
to the macro. I find it a little odd though that the vba seems to default to .Visible= False.

SilverSN95
07-29-2009, 10:59 AM
It looks like I just needed to add
wdApp.Visible = True
dest.Activate
to the macro. I find it a little odd though that the vba seems to default to .Visible= False.