J
jaberwocky
I'm using office 2003.
I have an Excel spreadsheet that contains data that are mailmerged into
a word document. To simplify the process for others, I made an EXCEL
macro that flags the active row, launches the mailmerged word
document(which filters all except the flagged data), merges to a new
document (fixing merge fields), and then closes the original document.
Only the last step fails. This should be the simplest step, and I've
tried using quotes to no avail. What am I doing wrong?
Sub MakeReferral()
'save row number in holdrow variable
holdrow = Selection.Row
Cells(holdrow, 101).Value = 1
Dim oWord As Word.Application
Dim myDoc As Word.Document
Set oWord = CreateObject("word.application")
oWord.Application.Visible = True
Set myDoc =
oWord.Application.Documents.Open("p:\aftercare\referral.doc")
With myDoc.ActiveWindow
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord =
ActiveDocument.MailMerge.DataSource.ActiveRecord
.LastRecord =
ActiveDocument.MailMerge.DataSource.ActiveRecord
End With
.Execute Pause:=False
End With
'close referral.doc
'*********************************************************************************
'this causes "runtime error '424'Object_required"
Windows(referral.doc).Close savechanges:=wdDoNotSaveChanges
End With
Set oWord = Nothing
'Clean up
Cells(holdrow, 101).Value = ""
End Sub
I have an Excel spreadsheet that contains data that are mailmerged into
a word document. To simplify the process for others, I made an EXCEL
macro that flags the active row, launches the mailmerged word
document(which filters all except the flagged data), merges to a new
document (fixing merge fields), and then closes the original document.
Only the last step fails. This should be the simplest step, and I've
tried using quotes to no avail. What am I doing wrong?
Sub MakeReferral()
'save row number in holdrow variable
holdrow = Selection.Row
Cells(holdrow, 101).Value = 1
Dim oWord As Word.Application
Dim myDoc As Word.Document
Set oWord = CreateObject("word.application")
oWord.Application.Visible = True
Set myDoc =
oWord.Application.Documents.Open("p:\aftercare\referral.doc")
With myDoc.ActiveWindow
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord =
ActiveDocument.MailMerge.DataSource.ActiveRecord
.LastRecord =
ActiveDocument.MailMerge.DataSource.ActiveRecord
End With
.Execute Pause:=False
End With
'close referral.doc
'*********************************************************************************
'this causes "runtime error '424'Object_required"
Windows(referral.doc).Close savechanges:=wdDoNotSaveChanges
End With
Set oWord = Nothing
'Clean up
Cells(holdrow, 101).Value = ""
End Sub