Automateing a Word Mail Merge

G

Guest

I have an application that puts data into an Excel spreadsheet. It then opens a Word doc that reads the data and either prints the resulting form letters or keeps the file open for viewing. This uses Office XP and worked fine until I applied SP3. now it crashes with the following error. "Requested object is not available" The crash occurs when I try to set the MailMerge.Destination. If I skip setting the destination the following message appears: "This method or property is not available because the document is not a mail merge main document." This tells me that I am now missing several steps.

Here is the code block that I have been using:

Dim wordApp As New Microsoft.Office.Interop.Word.Application
wordApp.Visible = True
Dim wordDoc As Microsoft.Office.Interop.Word.Document = wordApp.Documents.Open("formletter.doc", , True, False)

'Output the Mail Merge to the chosen destination
Try
If bolOutputPrinter Then
wordDoc.MailMerge.Destination = Microsoft.Office.Interop.Word.WdMailMergeDestination.wdSendToPrinter
wordDoc.MailMerge.Execute()
wordDoc.Close(False)
wordApp.Quit(False)
Else
wordDoc.MailMerge.Destination = Microsoft.Office.Interop.Word.WdMailMergeDestination.wdSendToNewDocument
wordDoc.MailMerge.Execute()
wordDoc.Close(False)
End If
Catch e As Exception
MessageBox.Show("An Exception Occurred in application, Please notify DB Admin of the following message: " & Chr(13) & Chr(13) & e.ToString, "Error in Application")
End Try


I have made sure that I am using the latest PIAs by downloading them from the following site: http://www.microsoft.com/downloads/...1E-3060-4F71-A6B4-01FEBA508E52&displaylang=en and installing them as per the instructions. I also refreshed the refferences in my application. I plan to use this type of reporting system in the future as it is easy to set up. However I need to know where I have gone wrong and what I need to do different when we migrate to Office 2003.

Please help,
Kaytrim
 
T

Telmo Sampaio

mmm... you also have a problem with your news reader. :)

Telmo Sampaio

Kaytrim said:
I have an application that puts data into an Excel spreadsheet. It then
opens a Word doc that reads the data and either prints the resulting form
letters or keeps the file open for viewing. This uses Office XP and worked
fine until I applied SP3. now it crashes with the following error.
"Requested object is not available" The crash occurs when I try to set the
MailMerge.Destination. If I skip setting the destination the following
message appears: "This method or property is not available because the
document is not a mail merge main document." This tells me that I am now
missing several steps.
Here is the code block that I have been using:

Dim wordApp As New Microsoft.Office.Interop.Word.Application
wordApp.Visible = True
Dim wordDoc As Microsoft.Office.Interop.Word.Document =
wordApp.Documents.Open("formletter.doc", , True, False)
'Output the Mail Merge to the chosen destination
Try
If bolOutputPrinter Then
wordDoc.MailMerge.Destination = Microsoft.Office.Interop.Word.WdMailMergeDestination.wdSendToPrinter
wordDoc.MailMerge.Execute()
wordDoc.Close(False)
wordApp.Quit(False)
Else
wordDoc.MailMerge.Destination = Microsoft.Office.Interop.Word.WdMailMergeDestination.wdSendToNewDocument
wordDoc.MailMerge.Execute()
wordDoc.Close(False)
End If
Catch e As Exception
MessageBox.Show("An Exception Occurred in application, Please
notify DB Admin of the following message: " & Chr(13) & Chr(13) &
e.ToString, "Error in Application")
End Try


I have made sure that I am using the latest PIAs by downloading them from
the following site:
http://www.microsoft.com/downloads/details.aspx?FamilyId=C41BD61E-3060-4F71-
A6B4-01FEBA508E52&displaylang=en and installing them as per the
instructions. I also refreshed the refferences in my application. I plan
to use this type of reporting system in the future as it is easy to set up.
However I need to know where I have gone wrong and what I need to do
different when we migrate to Office 2003.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top