Results 1 to 6 of 6

Thread: VB.NET and Mail Merge

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    38

    VB.NET and Mail Merge

    Hello,

    I wish to link my vb.net web application to word 2003 mail-merge function.

    What i specifically wish to do is have a form with some static textboxes and some dropdown lists. Then have a button called create label. When the user clicks this, the method links to a word template with mail merge fields and those fields are populated with the information on the web-form to create a label.

    Can this be done and how?

    Your help is much appreciated!

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB.NET and Mail Merge

    Yes, but you will need to have Word on your server and mailmerges with templates are tricky. You can use Bookmarks in your template and then just populate them but since your talking a mailmerge are you wanting to populate several documents at once?
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: VB.NET and Mail Merge

    This should give you a basic idea (at least get you on the right track). Write your merge data to a temporary .csv file to use as the data source, and then wipe it when you are done with it. Code is VBA/VB6, and I'll leave you to do the .NET version. sTemplate is the path to the template document, sTempfile is the temp data source.:
    VB Code:
    1. Dim oWord As Word.Application, oOut As Word.Document, oMerge As Word.MailMerge, oResult as Word.Document
    2.    
    3.     Set oWord = New Word.Application
    4.     Set oOut = oWord.Documents.Add(sTemplate, False, wdNewBlankDocument, False)
    5.     Set oMerge = oOut.MailMerge
    6.                                                                    
    7.     With oMerge
    8.         Call .OpenDataSource(sTempfile)
    9.         .Destination = wdSendToNewDocument
    10.         .Execute
    11.     End With
    12.  
    13.     Set oResult = oWord.ActiveDocument      'This is your merged document.
    14.     'Close and release ref'd objects.

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    38

    Re: VB.NET and Mail Merge

    in response to robdog888, i am oly merging to one word document when the submit button is clicked. So one label is created at a time and thus no need for loops or anything.

    Does that make it any simpler?

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB.NET and Mail Merge

    Yes, so using something like what comintern posted should be good just convert to .net.
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    38

    Re: VB.NET and Mail Merge

    i have no experience of vb6 and have just started with vb.net. Are the syntax's and structures the same. Can anyone help me further with the conversion.

    Thanks in advance!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width