|
-
Nov 11th, 2007, 08:08 PM
#1
Thread Starter
Junior Member
[RESOLVED] Mail Merge in vb.net
Hi, all, need your help. I have a very urgent problem to be solved.
i have collect a set of data from the db using vb.net and save it to a text file.
I also have a template ms word document.
What i would like to do is I want to merge the data in the text file to ms word template using vb.net script. will it be possible? if yes, then how should i do it?
Please, it is urgent. Thanks a lot.
-
Nov 11th, 2007, 08:10 PM
#2
Re: Mail Merge in vb.net
Yes, its possible but have you setup your template word doc as a mailmerge document?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 11th, 2007, 08:12 PM
#3
Thread Starter
Junior Member
Re: Mail Merge in vb.net
Hi, RobDog888,
Yes, i have already setup the template as a mailmerge document.
-
Nov 11th, 2007, 08:18 PM
#4
Re: Mail Merge in vb.net
Ok, next you will want to add a reference to MS Word xx.0 Object Library and automate it using the Word Object Model.
Then you will create the application instance, open the doc, and execute the MailMerge method.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 11th, 2007, 08:26 PM
#5
Re: Mail Merge in vb.net
Sorry, but that is for if you need to modify the data source or assign it dynamically. To just execute the merge you only need to open the document for printing etc.
System.Diagnostics.Process.Start("C:\Test.doc")
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 11th, 2007, 08:38 PM
#6
Thread Starter
Junior Member
Re: Mail Merge in vb.net
RobDog888,
let's say i generate the data then send it to a text file, later i open the template through vb.net, after that i want the vb.net side to do the mail merge from the data in the text file to word doc template. If like this i have to use the 1st method u suggested?
-
Nov 11th, 2007, 09:05 PM
#7
Re: Mail Merge in vb.net
If you keep the file name the same that you used to cinfigure the MM document then just simply starting the process is all thats needed. If you want to sort, change datasource locations, modify the mailerge in any way then you will need to use the WOM to do it.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 11th, 2007, 09:30 PM
#8
Thread Starter
Junior Member
Re: Mail Merge in vb.net
RobDog888,
It sounds like so easy to u..hahha.. so admire..
can you please explain in details? ee.. the best step by step, can?
I really need your help.
Thank you so much
-
Nov 11th, 2007, 09:49 PM
#9
Re: Mail Merge in vb.net
Step 1.
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oPSI As New System.Diagnostics.ProcessStartInfo
oPSI.FileName = "C:\MyTest.doc"
oPSI.UseShellExecute = True
oPSI.CreateNoWindow = True
oPSI.WindowStyle = ProcessWindowStyle.Hidden
oPSI.Verb = "print"
System.Diagnostics.Process.Start(oPSI)
End Sub
End Class
Step 2. Click the Yes button to run the query on your text file.
Step 3. retrieve printed pages from printer. 
References: My Office Dev. FAQs
http://vbforums.com/showthread.php?t=402094
http://vbforums.com/showthread.php?t=402097
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 11th, 2007, 10:29 PM
#10
Thread Starter
Junior Member
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
|