By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,572 Members | 1,516 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,572 IT Pros & Developers. It's quick & easy.

Automateing a Word Mail Merge

P: n/a
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.WdMailMergeDestinati on.wdSendToPrinter
wordDoc.MailMerge.Execute()
wordDoc.Close(False)
wordApp.Quit(False)
Else
wordDoc.MailMerge.Destination = Microsoft.Office.Interop.Word.WdMailMergeDestinati on.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/d...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
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


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

Telmo Sampaio

"Kaytrim" <Ka*****@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com...
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.WdMailMergeDestinati on.wdSendToPrinter wordDoc.MailMerge.Execute()
wordDoc.Close(False)
wordApp.Quit(False)
Else
wordDoc.MailMerge.Destination = Microsoft.Office.Interop.Word.WdMailMergeDestinati on.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/d...61E-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

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.