A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

"Word was unable to open the Excel data source" Asp.net Mailmerge



 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old June 17th, 2005, 11:14 AM
Shalini
external usenet poster
 
Posts: n/a
Default "Word was unable to open the Excel data source" Asp.net Mailmerge

Hi,

I am trying to perform word mail merge operation via ASP.Net using Excel as
data source.

Code is attached below:
Dim wrdApp As Word.Application
Dim wrdDoc As Word._Document
Dim wrdMailMerge As Word.MailMerge
Dim fileWORDName, fileEXCELName As Object

Try
wrdApp = New Word.Application


wrdApp.ChangeFileOpenDirectory("C:\Inetpub\wwwroot \FPA\Templates\")
fileWORDName = "ThankYou-Shalini.doc"

wrdDoc = wrdApp.Documents.Open(FileName:=fileWORDName,
ConfirmConversions:=False, ReadOnly _
:=False, AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate _
:="", Revert:=False, WritePasswordDocument:="",
WritePasswordTemplate:="" _
, Format:=Word.WdOpenFormat.wdOpenFormatAuto)

wrdMailMerge = wrdDoc.MailMerge
wrdMailMerge.MainDocumentType =
Word.WdMailMergeMainDocType.wdNotAMergeDocument

wrdApp.Visible = True
wrdDoc.ActiveWindow.Activate()
wrdDoc.ActiveWindow.Visible = True


wrdApp.ChangeFileOpenDirectory("C:\Inetpub\wwwroot \FPA\Archive\")
fileEXCELName = "FullfillmentReport1.xls"

wrdMailMerge.OpenDataSource(Name:= _
fileEXCELName, _
ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=Word.WdOpenFormat.wdOpenFormatAuto, Connection:= _
"DSN=Excel
Files;DBQ=fileEXCELName;DriverId=790;MaxBufferSize =2048;PageTimeout=5;" _
, SQLStatement:="SELECT * FROM 'Data'", SQLStatement1:="")



' Perform mail merge.
wrdMailMerge.Destination =
Word.WdMailMergeDestination.wdSendToNewDocument
wrdMailMerge.MainDocumentType =
Word.WdMailMergeMainDocType.wdFormLetters

wrdMailMerge.SuppressBlankLines = True

wrdMailMerge.DataSource.FirstRecord =
Word.WdMailMergeDefaultRecord.wdDefaultFirstRecord
wrdMailMerge.DataSource.LastRecord =
Word.WdMailMergeDefaultRecord.wdDefaultLastRecord


wrdMailMerge.Execute(False)

' Close the original form document.
wrdDoc.Saved = True
wrdDoc.Close(False)

Catch ex As Exception
Response.Write(ex.ToString)
Dim AllWORDProcess() As System.Diagnostics.Process =
System.Diagnostics.Process.GetProcessesByName("WIN WORD")
Dim WordProcess As New System.Diagnostics.Process
For Each WordProcess In AllWORDProcess
WordProcess.Kill()
Next
WordProcess.Close()

Dim AllEXCELProcess() As System.Diagnostics.Process =
System.Diagnostics.Process.GetProcessesByName("Exc el")
Dim ExcelProcess As New System.Diagnostics.Process
For Each ExcelProcess In AllEXCELProcess
ExcelProcess.Kill()
Next
ExcelProcess.Close()
Finally
' Release References.
wrdMailMerge = Nothing
wrdDoc = Nothing
wrdApp = Nothing
End Try


Please do the needful
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
mailmerge with txtfile bilisa Mailmerge 7 May 6th, 2005 10:12 PM
How to change merge forms from Word Perfect to Microsoft Word Charles Kenyon General Discussion 1 December 30th, 2004 03:35 PM
Automatically Updating Excel Data In Word Doc Inside Excel File Business Design Architect General Discussion 0 August 29th, 2004 10:55 PM
How to run word and pass a mail merge values and fax it to the recipient Belinda Mailmerge 2 June 13th, 2004 12:49 AM
Mial merge data base problems Rachael Mailmerge 16 May 21st, 2004 06:22 PM


All times are GMT +1. The time now is 02:29 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.