|
-
Mar 6th, 2003, 04:30 PM
#1
Thread Starter
Junior Member
Any know how to do MailMerge ? Urgently required
Hi,
Does anyone know how to perform Mail Merge to Word template in VB.Net.?
Basically after filling in my dataset. I would like to open the word temaplet, loop through the dataset, fill in the value to the book marks created in the template and loop back again.
If I have 100 records in my dataset, I would like t have 100 pages of one document rather 100 word documents of one page each.
I hope I make sense, an early response will be very much appreciated.
Thanks in advance
-
Mar 6th, 2003, 05:24 PM
#2
can you upload the word template?
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Mar 6th, 2003, 05:43 PM
#3
Thread Starter
Junior Member
Well it could be any word template I suppose.
I would be given user a choice to what template to select and what fields from SQL database to retreive. And then perform the Mail Merge action to Word temaplate whatever the user has selected.
If you have any example for this action would be really helpfull.
Thanks
-
Mar 6th, 2003, 07:33 PM
#4
ahh.. I see what your after.
hmmm.... let me think about it. I could do in in VB6...so im sure it can be done in .net
are you using Office 2000? XP? (I only have 2000 but that should be able to be used with office XP)
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Mar 6th, 2003, 09:39 PM
#5
ok..have you been able to even launch word from vb.net?
the only thing I have found is a download that included a file called: Interop.Word.dll
http://msdn.microsoft.com/library/de...mateoffice.asp
(download the sample)
this file is a needed reference to even get the
Dim wrd as New Word.Application
to work?
not sure why I couldnt get it otherwise....
unless someone else has figured this out....
Last edited by Static; Mar 6th, 2003 at 09:43 PM.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Mar 6th, 2003, 09:47 PM
#6
wwoops.. "Pay no atention to theman behind the curtain"
lol
I found them in the references
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Mar 6th, 2003, 10:16 PM
#7
ok... heres a start:
VB Code:
Dim wrd As New Word.Application
wrd.Visible = True
wrd.Documents.Add()
wrd.ActiveDocument.MailMerge.MainDocumentType = Word.WdMailMergeMainDocType.wdMailingLabels
wrd.ActiveDocument.MailMerge.OpenDataSource(Name:="[b]C:\Path to datafile.doc[/b]", PasswordDocument:="", WritePasswordDocument:="", SQLStatement:="" & "", Connection:="", LinkToSource:=True)
wrd.ActiveDocument.DataForm()
wrd.ActiveDocument.MailMerge.Fields.Add(Range:=wrd.Selection.Range, Name:="Title")
wrd.Selection.TypeText(Text:=" ")
wrd.ActiveDocument.MailMerge.Fields.Add(Range:=wrd.Selection.Range, Name:="FirstName")
wrd.Selection.TypeText(Text:=" ")
wrd.ActiveDocument.MailMerge.Fields.Add(Range:=wrd.Selection.Range, Name:="LastName")
wrd.Selection.TypeParagraph()
wrd.ActiveDocument.MailMerge.Fields.Add(Range:=wrd.Selection.Range, Name:="Address1")
wrd.Selection.TypeParagraph()
wrd.ActiveDocument.MailMerge.Fields.Add(Range:=wrd.Selection.Range, Name:="City")
wrd.Selection.TypeText(Text:=", ")
wrd.ActiveDocument.MailMerge.Fields.Add(Range:=wrd.Selection.Range, Name:="State")
wrd.Selection.TypeText(Text:=" ")
wrd.ActiveDocument.MailMerge.Fields.Add(Range:=wrd.Selection.Range, Name:="PostalCode")
wrd.Selection.TypeParagraph()
With wrd.ActiveDocument.MailMerge
.Destination = Word.WdMailMergeDestination.wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = Word.WdMailMergeDefaultRecord.wdDefaultFirstRecord
.LastRecord = Word.WdMailMergeDefaultRecord.wdDefaultLastRecord
End With
.Execute(Pause:=True)
End With
the best thing to do....
record a macro... then do what you need...then view the code.
thats almost what I did above...it is close to working (the data of my 3 customers disappeared but..)
let me know if you need more help
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Mar 7th, 2003, 11:03 AM
#8
Thread Starter
Junior Member
Thanks a lot man.
I was facing the problem, I couldn't get Dim wrd As New Word.Application this working in .Net and thanks for your insight.
I will give it a shot and will let you know how it goes.
-
Mar 7th, 2003, 11:28 AM
#9
Thread Starter
Junior Member
I tried adding the word refernce libary but it won't let me add it, it fails by displaying an error message that failed to conver to type library, please have a look at the attachment. It's a screen shot of the error message.
-
Mar 7th, 2003, 11:31 AM
#10
Thread Starter
Junior Member
ooops here is the attachment
-
Mar 7th, 2003, 11:35 AM
#11
lol...where is the attachment?
Are you adding the Microsoft word 9.0 etc... reference?
well..Try downloading the example from Microsoft...
and swipe the Interop.Word.dll from it.
then use browse to add it as a reference...that should work
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Mar 7th, 2003, 11:41 AM
#12
Thread Starter
Junior Member
It seems like it worked just by grabbing the word.dll and adding to my project.
I'll proceed with my application and will let you know the progress.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|