Opening a document with Word 2003 from VBA

Geoff Convery

Registered User.
Local time
Today, 15:58
Joined
Jul 21, 2006
Messages
33
I've an application which extracts to Excel then opens a mailmerge template to print documents using that information. I had it working for both Word 2000 and Word 2007 specifying different ways of opening Word depending on the version. I used Shell to open the 2000 version

Shell locWordProcessorPath & " " & locMailmergeDocPath, vbNormalFocus

where locWordProcessorPath and locMailmergeDocPath are the paths to Word 2000 and the mailmerge documents respectively

However I had to set Word as an object to open the 2007 version. using the following function

Sub OpenWordDoc(strDocPath As String)
Dim objApp As Object
Set objApp = CreateObject("Word.Application")
objApp.Visible = True
objApp.Documents.Open strDocPath
End Sub

The users have now presented me with a computer with 2003 installed and the default Shell method isn't working. I would set this computer up to use the 2007 method but the testing is a bit cumbersome. Can you suggest whether 2003 should work like 2007 or do I have to think again?
 
You can fully manage a mail merge within Access. I use the following code....

'This is the variable which contains the name of the mail merge document
Dim strTemplate as String

Set objApp = CreateObject("Word.Application")
With objApp
.Visible = True
'The mail merge document is opened
.Documents.Open strTempfolder
'The document is merged with the field form the SQL statement in the current
database
.ActiveDocument.MailMerge.OpenDataSource Name:=CurrentDb.Name, & _
SQLStatement:="SELECT * FROM <Table>"
'The result is send to a new document
.ActiveDocument.MailMerge.Destination = wdSendToNewDocument
.ActiveDocument.MailMerge.Execute Pause:=True
'The active document in Word is set to the merge document
.Documents(strTemplate).Activate
'It is closed without saving
.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
End With

'And the Word object is cleared
Set objApp = Nothing

Is this any help?
 
Hi I do not profess to be an expert but, I use ac2003 to open my word documents and is appears to be similar to yours with a slight variation and is as follows:

Dim oApp As Object
Set oApp = CreateObject("Word.Application")
With oApp
oApp.Visible = True
.Documents.Open FileName:="C:\nameoffolder\nameofdocument"


Exit_Command14_Click:
Exit Sub
Err_Command14_Click:
MsgBox Err.Description
Resume Exit_Command14_Click
End With
end sub
Hope this is of some use.
 

Users who are viewing this thread

Back
Top Bottom