View Full Version : Running a Macro in Word On Open


duecesup
11-20-2008, 01:56 PM
Hello all,
I have created a report in Access and have exported the document to word for editing. However, I need to complete a mail merge in word to see all of my entries. I have created a macro of the mail merge but need to know how to run the macro automatically when the Word document is opened.
Any suggestions
Thanks

johncallaghan
01-06-2009, 02:56 AM
Why not open Word from within Access and then place bookmarks where you want to insert data and then use something like this precedure to insert the text.
MsObjDoc is a global variable the Word.Document that is open.
Public Sub InsertText(BookMk As String, TextToInsert As String)
Dim WordRange As Word.Range
If MsObjDoc.Bookmarks.Exists(BookMk) Then
Set WordRange = MsObjDoc.GoTo(What:=wdGoToBookmark, name:=BookMk)
WordRange.InsertAfter TextToInsert
End If
End Sub

Cheers

john