Call a specific Word file from an Excel file using VBA

rgrovier

New Member
Joined
Sep 13, 2006
Messages
15
I have an Excel file that serves as a data source for a Word mailmerge. I would like to have the Excel VBA program open the Word document after closing the Excel file so that my users can complete the mailmerge.

Any thoughts? Thanks.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Sub OpenWordDoc()
'In order to use this code you must set a reference to the
'Word object library by doing this. In the VB Editor click
'Tools, References. Then search for Microsoft Word n.n Object Library
'where n.n will depend on your version of Word.

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:\temp\anyolddoc.doc")

wdApp.Visible = True

'You can now do whatever you like with the Word document e.g.

wdDoc.PrintOut
wdDoc.SaveAs "C:\temp\hello.doc"
wdDoc.Activate
'etc

End Sub

I found this for ya see if that helps ya out
 
Upvote 0
Sub myOpenWordDoc()
'Standard Sheet module, like: Sheet1.
Dim wApp As Object, fs As Object
Dim myDocFound As Boolean
Dim myDocDriveFolderNameExt$

myDocDriveFolderNameExt = "C:/My Files/JSW/Excel/Data/summary7.doc"

On Error GoTo myErr
Set fs = CreateObject("Scripting.FileSystemObject")
Set wApp = CreateObject("Word.Application")

myDocFound = fs.FileExists(myDocDriveFolderNameExt)

If myDocFound = True Then
wApp.Documents.Open myDocDriveFolderNameExt, ReadOnly:=False
wApp.Visible = True
Exit Sub
Else

MsgBox "The WORD document : " & myDocDriveFolderNameExt & ", was not found", _
, vbCritical + vbOKOnly, "Open File Error!"
Exit Sub
End If

myErr:
MsgBox "An Error Occurred opening your WORD file!", _
vbCritical + vbOKOnly, "Open File Error!"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,649
Members
448,975
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top