Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8280443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:40:47+00:00 2026-06-08T09:40:47+00:00

I’m trying to create word documents on the fly in VB.NET, and I’ve found

  • 0

I’m trying to create word documents on the fly in VB.NET, and I’ve found that the documentation on all of this seems very scarce. Right now my program works by looping through a database table, and for each row it pulls out the variables. The program then loops through and parses a template word doc, replacing variables in that template with variables from the database, then saving as a new doc.

Instead, for every “new doc” that I would be creating, I want to just append it onto another doc, that way when it comes time to parse 1000 rows in the table, I don’t have to create and save 1000 different word documents to the filesystem.

I can’t seem to find anything out there about this. Everything mentions merging documents (I actually want to append, not merge) or the only way I can append (“Insert”) a document is by using WordApplication.Selection.InsertFile(newWordDocument.FullName). This works, but requires me to save newWordDocument to the filesystem before inserting it.

Is there a way to, while still in memory, add newWordDocument to my WordApplication object?

Here’s the pseudocode of what I have now

For each row in TableOfVariables
Dim WordApplication as New Word.Application
Dim tempDoc as New Word.Document
tempDoc = WordApplication.Documents.Add
tempDoc = fillVariablesOfTheDocument(tempDoc, row)
tempDoc.Save() 'This is the problem - it saves as a new file rather than appending into WordApplication
Next
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:40:50+00:00Added an answer on June 8, 2026 at 9:40 am

    Took a while, but somehow I found out about MailMerge, which I had no idea existed. Long story short, I can have a template document with variables, and I can have an input excel document. The excel document will have a header row which contains the variable names, and each individual cell of the excel doc will represent the variable that will go into the document. When I execute MailMerge, the template will be replaced with n amount of pages (where n is the number of excel rows). This solves my problem of adding multiple documents to 1 big excel document. I tested this with 1,000 rows in my excel doc, and it worked flawlessly.

    Here’s the code I ended up with:

            Dim wrdSelection As Word.Selection
            Dim wrdMailMerge As Word.MailMerge
            Dim wrdMergeFields As Word.MailMergeFields
    
            ' Create an instance of Word  and make it visible.
            wrdAppMailMrg = CreateObject("Word.Application")
            wrdAppMailMrg.Visible = True
    
            ' Add a new document.
            wrdDocMailMrg = wrdAppMailMrg.Documents.Open("Template.docx")
            wrdDocMailMrg.Select()
    
            wrdSelection = wrdAppMailMrg.Selection()
            wrdMailMerge = wrdDocMailMrg.MailMerge()
    
            'Open Data Source
            wrdDocMailMrg.MailMerge.OpenDataSource("InputVariables.xlsx", SQLStatement:="SELECT * FROM [Sheet1$]")
    
            ' Perform mail merge.
            wrdMailMerge.Destination = _
                       Word.WdMailMergeDestination.wdSendToNewDocument
            wrdMailMerge.Execute(False)
    
            ' Close the original form document.
            wrdDocMailMrg.Saved = True
            wrdDocMailMrg.Close(False)
    
            ' Release References.
            wrdSelection = Nothing
            wrdMailMerge = Nothing
            wrdMergeFields = Nothing
            wrdDocMailMrg = Nothing
            wrdAppMailMrg = Nothing
    

    Now I just have to tweak it to make it run faster and clean up the UI, but the functionality is completely there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I am trying to loop through a bunch of documents I have to put
I know there's a lot of other questions out there that deal with this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.