+ Reply to Thread
Results 1 to 8 of 8

Populate Word Document from Excel

  1. #1
    Registered User
    Join Date
    12-26-2006
    Posts
    54

    Populate Word Document from Excel

    Hello,

    I have an Excel sheet that contains data per row. At the end of each row, I want to put a button (or a hyperlink to a file) that will put the data from that row into a new Word document, something like a printer-friendly document.

    Please find enclosed the Excel file and the DOC format that I need.
    Attached Files Attached Files

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    A single button would suffice though you can go to all that trouble if you like. There are 2 approaches, (1) Mail Merge and (2) Write to foreground in a new doc. (2) is probably the easiest for such a simple doc.

    Record a macro and then insert the parts for the data. When you add the dummy data in the recording, type F1 for Field1's data, F2 for Field2 and so on. The user would select any cell from a row and run the macro. F1 and F2 values are found by:
    Please Login or Register  to view this content.
    Of course other methods like ranges for the field values could be used as well.

    If you need more help, post back.

  3. #3
    Forum Contributor beeawwb's Avatar
    Join Date
    01-04-2004
    Location
    Perth, WA, Australia
    MS-Off Ver
    Microsoft Office Excel 2003 (11.8146.8221) SP2
    Posts
    105
    To take it a step further, why not create your "printer document" as a Word template (see attached: carpage.dot) with form fields. Then using the values obtained (As above) copy the values into the fields using the field bookmarks.

    I'm not 100% sure on how to do this myself (I can get as far as creating the Word.Application, but get stuck) but I'm sure somebody here would know how.

    -Bob
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    12-26-2006
    Posts
    54
    Quote Originally Posted by beeawwb
    To take it a step further, why not create your "printer document" as a Word template (see attached: carpage.dot) with form fields. Then using the values obtained (As above) copy the values into the fields using the field bookmarks.

    -Bob
    Yes, this is what I want. But I am not good in VB codes etc.,

  5. #5
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    Here is the method that I detailed. If you don't know MSWord syntax, just record a macro in it like you would in Excel. The only key that you need is how to reference the object.

    Right click your sheet's tab, Insert Code, and put this code into the worksheet object. Then, just click a cell in Column I to generate the doc.

    If you need to change column I without triggering the macro, change the name of the Sub and then change it back when ready to activate the SelectionChange event. This will let you put simulated Hypertext into the cells.

    You only need to add the reference if you use the early binding method. Uncomment those 2 lines and comment the 2 late binding lines in that case.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    03-27-2019
    Location
    Texas
    MS-Off Ver
    Excel 2016
    Posts
    5

    Re: Populate Word Document from Excel

    Why is it not recommended to use an existing instance of microsoft word?

  7. #7
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Populate Word Document from Excel

    Since wa is set to nothing at the end, word application closes. What if you had not saved other docs that were open?

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Populate Word Document from Excel

    Quote Originally Posted by MH2020 View Post
    Why is it not recommended to use an existing instance of microsoft word?
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original. Please start a new thread - See Forum rule #4

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1