Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / December 2004

Tip: Looking for answers? Try searching our database.

Requested object is not available - automating word mail merge

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Davy - 29 Nov 2004 23:26 GMT
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(object sender, System.EventArgs e)
{
Word.Application wrdApp;
Word._Document wrdDoc;
Word.MailMerge wrdMailMerge;
Object oMissing = System.Reflection.Missing.Value;
Object oFalse = false;
Object oTrue = true;
Object oFormat = 0;
Object oNul = null;
String cTextFile = "d:\netmerge\test.txt";
Object oDocName = "test.doc";

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

// Add a new document.
wrdDoc = wrdApp.Documents.Add(ref oMissing,ref oMissing,ref oMissing,ref
oMissing);
wrdDoc.SaveAs(ref 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.MailMerge;
wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToPrinter;

//Connect to data
/* OpenDataSource parameters
TableName ,
Format ,
ConfirmConversions ,
ReadOnly ,
LinkToSource ,
AddToRecentFiles ,
PasswordDocument ,
PasswordTemplate ,
Revert ,
WritePasswordDocument ,
WritePasswordTemplate ,
Connection ,
SQLStatement ,
SQLStatement1 ,
OpenExclusive ,
SubType
*/

//problem ooccurs here
wrdMailMerge.OpenDataSource(cTextFile,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.Execute(ref oFalse);

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

// Release References.
wrdMailMerge = null;
wrdDoc = null;
wrdApp = null;
}
doug mansell - 02 Dec 2004 09:22 GMT
just guessing...but try changing this line:

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

to

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

> 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
[quoted text clipped - 80 lines]
> wrdApp = null;
> }

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.