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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

rflyr98

New Member
Joined
Sep 24, 2006
Messages
6
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
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
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
 

Forum statistics

Threads
1,136,995
Messages
5,679,037
Members
419,801
Latest member
spinjector

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
Top