My code is as follows:
Function RunWordMacro()
Dim WordApp As Object
Dim WordDoc As Object
Set WordApp = CreateObject("Word.Application")
Set WordDoc = WordApp.Documents.Open _
("S:\MGMTSRV\INDIVIDUAL STAFF PROJECTS\MSwagle1\mailmerge.docm")
WordApp.Visible = True
With WordApp.ActiveWindow
.Selection.WholeStory
.Selection.TypeText Text:="Dear Dr. "
.ActveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _
, Text:="""LAST_NAME"""
.Selection.TypeText Text:=","
.Selection.TypeText Text:=Chr(11)
.Selection.TypeText Text:=Chr(11)
.Selection.TypeText Text:=vbTab
.Selection.TypeText Text:="Your first surgery is on "
.ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _
, Text:="""MinOfSCHED_CASE_START"""
.Selection.TypeText Text:="."
.Selection.TypeText Text:=Chr(11)
.Selection.TypeText Text:=Chr(11)
.Selection.TypeText Text:="Thank You."
With .ActiveDocument.MailMerge
.Destination = wdSendToEmail
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
End With
End With
Set WordApp = Nothing
End Function
I'm trying to automate a Word Mail Merge through access. I keep getting the error 424 on the lines with wd in them. I've read in other threads that you go to Tools and References to fix this, but I can't click References. Please let me know.
Thanks!
Function RunWordMacro()
Dim WordApp As Object
Dim WordDoc As Object
Set WordApp = CreateObject("Word.Application")
Set WordDoc = WordApp.Documents.Open _
("S:\MGMTSRV\INDIVIDUAL STAFF PROJECTS\MSwagle1\mailmerge.docm")
WordApp.Visible = True
With WordApp.ActiveWindow
.Selection.WholeStory
.Selection.TypeText Text:="Dear Dr. "
.ActveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _
, Text:="""LAST_NAME"""
.Selection.TypeText Text:=","
.Selection.TypeText Text:=Chr(11)
.Selection.TypeText Text:=Chr(11)
.Selection.TypeText Text:=vbTab
.Selection.TypeText Text:="Your first surgery is on "
.ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _
, Text:="""MinOfSCHED_CASE_START"""
.Selection.TypeText Text:="."
.Selection.TypeText Text:=Chr(11)
.Selection.TypeText Text:=Chr(11)
.Selection.TypeText Text:="Thank You."
With .ActiveDocument.MailMerge
.Destination = wdSendToEmail
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
End With
End With
Set WordApp = Nothing
End Function
Thanks!