Opening Word with a specific document from excel vba

  • Thread starter Thread starter JRB
  • Start date Start date
J

JRB

Is it possible to open Word with a specific document from an excel procedure

I have managed to open word using:
Application.ActivateMicrosoftApp xlMicrosoftWord
but can find no way to specify the document to load

I would like to run a mail merge, using Word, to create some mailing labels,
print them and then return to Excel and closing the Word program

Any (and all) suggestions greatly appreciated

TIA
 
I omitted to mention that the procedures have to be compatible with Excel 97
 
Hi JRB

Try this example that print a Word file

Sub test()
Dim WD As Object
Set WD = CreateObject("Word.Application")
WD.Documents.Open ("C:\ron.doc")
WD.ActiveDocument.PrintOut Background:=False
WD.ActiveDocument.Close
WD.Quit
Set WD = Nothing
End Sub
 
Thanks Ron ... That definitely works a treat
Unfortunately it printed the document before the mailmerge took place
Have you any suggestions as to how I can force the mailmerge prior to
printing

Thanks again from the prompt and accurate response
This NG must be one of the best
 
To open the word application and then a specific document I use late
binding and the following code (you need to replace
"H:\DriveName\FolderName\MyDocument.Doc" with your own document and
pathway):

Dim WordApplication As Object

Sub OpenFileNote()

Call OpenWord

With WordApplication
.WindowState = 1
.Visible = True
.documents.Open
Filename:="H:\DriveName\FolderName\MyDocument.Doc"
End With

End Sub

Private Function OpenWord()

Dim strApp As String
strApp = "Word.Application"
'check to see if Word is running
On Error Resume Next
If Not IsRunning(strApp) Then
Set WordApplication = CreateObject(strApp)
Else
Set WordApplication = GetObject(, strApp)
End If
On Error GoTo 0
strApp = ""

End Function

Public Function IsRunning(ByVal myAppl As String) As Boolean

Dim applRef As Object
On Error Resume Next

Set applRef = GetObject(, myAppl)

If Err.Number = 429 Then
IsRunning = False
Else
IsRunning = True
End If

Set applRef = Nothing

End Function

(EARLY BINDING IS THE OTHER APPROACH)

HOPE THIS HELPS
JASON
 

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

Back
Top