I receive this error message when running my progress code - "Microsoft Visual Basic Run-Time Error '5852': Requested Object is Not Available"...when I choose Debug it indicates ".Destination = wdSendToNewDocument" is the problem. The macro runs without errors when executed from Word.
The macro opens C:\edm0034.doc then uses C:\jobprwk.xls for Mail Merge then Prints the merged document and closes the files. I have attached those 2 files to help with troubleshooting.
/* MY PROGRESS CODE */
def var word as com-handle.
create "word.application" word.
word:Visible = false.
wordisplayAlerts = false.
word:run("'normal.dot'!solar_hc").
pause 15 message "HardCard Printing...Please Wait!".
word:quit().
release object word.
/* MY WORD MACRO */
Sub Solar_HC()
ChangeFileOpenDirectory "C:\"
Documents.Open FileName:="edm0034.doc", ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
ActiveDocument.PrintOut
ActiveWindow.Close
ActiveWindow.Close
End Sub
The macro opens C:\edm0034.doc then uses C:\jobprwk.xls for Mail Merge then Prints the merged document and closes the files. I have attached those 2 files to help with troubleshooting.
/* MY PROGRESS CODE */
def var word as com-handle.
create "word.application" word.
word:Visible = false.
wordisplayAlerts = false.
word:run("'normal.dot'!solar_hc").
pause 15 message "HardCard Printing...Please Wait!".
word:quit().
release object word.
/* MY WORD MACRO */
Sub Solar_HC()
ChangeFileOpenDirectory "C:\"
Documents.Open FileName:="edm0034.doc", ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
ActiveDocument.PrintOut
ActiveWindow.Close
ActiveWindow.Close
End Sub