473,790 Members | 3,200 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Requested object is not available - automating word mail merge

I am trying to set up a mail merge by automation using a text file as the
data source but I keep getting the message

"Requested object is not available" and the debugger stops on the
opendatasource line (code below)

(I am VERY new to c# so this is a bit difficult for me at the moment)

I am using win xp and office xp 2003 (word 11)
I have installed the PIA for office as per Microsoft KB

Any help would be appreciated

Cheers
John
-----------------------------------------------------------------------------------------------
private void button1_Click(o bject sender, System.EventArg s e)
{
Word.Applicatio n wrdApp;
Word._Document wrdDoc;
Word.MailMerge wrdMailMerge;
Object oMissing = System.Reflecti on.Missing.Valu e;
Object oFalse = false;
Object oTrue = true;
Object oFormat = 0;
Object oNul = null;
String cTextFile = "d:\netmerge\te st.txt";
Object oDocName = "test.doc";

// Create an instance of Word and make it visible.
wrdApp = new Word.Applicatio n();
wrdApp.Visible = true;

// Add a new document.
wrdDoc = wrdApp.Document s.Add(ref oMissing,ref oMissing,ref oMissing,ref
oMissing);
wrdDoc.SaveAs(r ef oDocName,ref oMissing,ref oMissing,ref oMissing,ref
oFalse,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref
oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing);
wrdDoc.Select() ;

// Set Up Mail Merge
wrdMailMerge = wrdDoc.MailMerg e;
wrdMailMerge.De stination = Word.WdMailMerg eDestination.wd SendToPrinter;

//Connect to data
/* OpenDataSource parameters
TableName ,
Format ,
ConfirmConversi ons ,
ReadOnly ,
LinkToSource ,
AddToRecentFile s ,
PasswordDocumen t ,
PasswordTemplat e ,
Revert ,
WritePasswordDo cument ,
WritePasswordTe mplate ,
Connection ,
SQLStatement ,
SQLStatement1 ,
OpenExclusive ,
SubType
*/

//problem ooccurs here
wrdMailMerge.Op enDataSource(cT extFile,ref oFormat,ref oFalse,ref oFalse,ref
oTrue,ref oFalse,ref oNul,ref oNul,
ref oFalse,ref oNul,ref oNul,ref oNul,ref oNul,ref oNul,ref oFalse,ref
oNul) ;

//Perform mail merge.
wrdMailMerge.Ex ecute(ref oFalse);

// Close the original form document.
wrdDoc.Saved = true;
wrdDoc.Close(re f oFalse,ref oMissing,ref oMissing);

// Release References.
wrdMailMerge = null;
wrdDoc = null;
wrdApp = null;
}

Nov 17 '05 #1
1 2707
just guessing...but try changing this line:

String cTextFile = "d:\netmerge\te st.txt";

to

String cTextFile = "d:\\netmerge\\ test.txt";

John Davy wrote:
I am trying to set up a mail merge by automation using a text file as the
data source but I keep getting the message

"Requested object is not available" and the debugger stops on the
opendatasource line (code below)

(I am VERY new to c# so this is a bit difficult for me at the moment)

I am using win xp and office xp 2003 (word 11)
I have installed the PIA for office as per Microsoft KB

Any help would be appreciated

Cheers
John
-----------------------------------------------------------------------------------------------
private void button1_Click(o bject sender, System.EventArg s e)
{
Word.Applicatio n wrdApp;
Word._Document wrdDoc;
Word.MailMerge wrdMailMerge;
Object oMissing = System.Reflecti on.Missing.Valu e;
Object oFalse = false;
Object oTrue = true;
Object oFormat = 0;
Object oNul = null;
String cTextFile = "d:\netmerge\te st.txt";
Object oDocName = "test.doc";

// Create an instance of Word and make it visible.
wrdApp = new Word.Applicatio n();
wrdApp.Visible = true;

// Add a new document.
wrdDoc = wrdApp.Document s.Add(ref oMissing,ref oMissing,ref oMissing,ref
oMissing);
wrdDoc.SaveAs(r ef oDocName,ref oMissing,ref oMissing,ref oMissing,ref
oFalse,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref
oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing);
wrdDoc.Select() ;

// Set Up Mail Merge
wrdMailMerge = wrdDoc.MailMerg e;
wrdMailMerge.De stination = Word.WdMailMerg eDestination.wd SendToPrinter;

//Connect to data
/* OpenDataSource parameters
TableName ,
Format ,
ConfirmConversi ons ,
ReadOnly ,
LinkToSource ,
AddToRecentFile s ,
PasswordDocumen t ,
PasswordTemplat e ,
Revert ,
WritePasswordDo cument ,
WritePasswordTe mplate ,
Connection ,
SQLStatement ,
SQLStatement1 ,
OpenExclusive ,
SubType
*/

//problem ooccurs here
wrdMailMerge.Op enDataSource(cT extFile,ref oFormat,ref oFalse,ref oFalse,ref
oTrue,ref oFalse,ref oNul,ref oNul,
ref oFalse,ref oNul,ref oNul,ref oNul,ref oNul,ref oNul,ref oFalse,ref
oNul) ;

//Perform mail merge.
wrdMailMerge.Ex ecute(ref oFalse);

// Close the original form document.
wrdDoc.Saved = true;
wrdDoc.Close(re f oFalse,ref oMissing,ref oMissing);

// Release References.
wrdMailMerge = null;
wrdDoc = null;
wrdApp = null;
}

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
12528
by: Steve M | last post by:
I'm trying to do invoke the mail merge functionality of MS Word from a Python script. The situation is that I have a template Word document, and a record that I've generated in Python, and I want to output a new Word .doc file with the template filled in with the record I've generated. (To refresh your memory, in Word a mailmerge is achieved by a) under Tools -> Letters and Mailings, check off Show Mail Merge Toolbar; b) open a document...
6
2764
by: MLH | last post by:
I would like to use a utility that can read tables inside an Access 97 mdb file. Writing not necessary. No other objects need to be readable - only tables. Anybody know of a freeware utility?
1
12255
by: John Welch | last post by:
I'm trying to use the Mergit() function from the MS Knowledge base article to merge data from a query or table in my Access 2000 mdb into an existing word merge document. Every time it runs it brings up the dialog "Confirm Data Source", and asks if I want to use OLE, DDE, or ODBC. If I say ODBC, it then asks me for the table name. If I do all that, the merge works correctly, but I don't want users to have to do all that. I thought the...
0
2206
by: mbbostwick | last post by:
I have a problem with a mail merge procedure I used to use with Access '97. We recently converted to Office XP (2002) and I now have an issue I am unfamilliar with and have been unable to resolve. I am trying to merge individual records into seperate mail merge word docs. In the past I linked my word files directly to the tables and then simply changed the QueryString of the merge file for the particular record I need to create a...
8
13337
by: Ron B | last post by:
Help!!! What am I doing wrong? I am working with Office 2003 and am trying to create a command button on an Access form that will create a mail merge in Word from an Access table. I want to make the mail merge seamless to the user so all they have to do is click on the command button and the letters are generated. For the button I created an event procedure with the following code: Private Sub RunLetters_Click()
6
4649
by: crealesmith | last post by:
Firstly, I have no problem with mail merging to Word, VB code for that works perfectly. On one mail merge I need to merge 15 fields of data that are from 3 seperate records. The 3 records are all in the same table. If I use a control source that is selecting the 3 records, all of the data is shown but spread over 3 pages in the mail merge, but needs to be listed together in one paragraph. Is there anyway of looping through the 3...
7
4167
by: =?Utf-8?B?QmFkaXM=?= | last post by:
Hi, I'm trying to follow a mail merging example in C#.Net that I got from: http://support.microsoft.com/default.aspx/kb/301659 and in one the methods: Word.Application wrdApp; Word._Document wrdDoc; Object oMissing = System.Reflection.Missing.Value; Object oFalse = false;
2
1830
by: chutney | last post by:
Dear all, please excuse the fact that this is not an explicit problem I have, but more of a general query. I have an Access database (2003) with a load of contact details in it. Including various fields for each contact, such as services they offer, where they are, main contact name etc. Some of these contact details will be out of date and I want to make sure that all the contact details are up-to-date. I am in the process of setting...
1
2053
by: TommyGunn | last post by:
Hi everyone, Is there anyway to automatically put Access data into Mail Merge in an existing Word doc with content? I have bits and pieces of this done, but I can't seem to put it all together. I am able to manually export an Access Query to Word, and the mail merge works fine. I am also able to open Word from Access, but unfortunately the Mail Merge data does not get updated since the manual export (thinking a few days later when the...
0
10419
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10201
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10147
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9987
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9023
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6770
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.