Consulting

Results 1 to 2 of 2

Thread: VBA Extract from Excel and Paste into a Word Template

  1. #1
    VBAX Regular
    Joined
    Jul 2017
    Posts
    11
    Location

    VBA Extract from Excel and Paste into a Word Template

    Hi,

    I was wondering if it is possible to write a macro that extracts certain values from a each row of an Excel sheet and pastes them as text into a pre-prepared word template, under specific headings. I attach the before, template, and end result examples here, with suggestion for possible rules on the excel sheet.

    Thank you for your help!
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    You probably don't need code for this! Instead, you could use Word's Catalogue/Directory Mailmerge facility (the terminology depends on the Word version). To see how to do so with any mailmerge data source supported by Word, check out my Microsoft Word Catalogue/Directory Mailmerge Tutorial at:
    https://www.msofficeforums.com/mail-merge/38721-microsoft-word-catalogue-directory-mailmerge-tutorial.html
    or:
    http://www.gmayor.com/Zips/Catalogue%20Mailmerge.zip
    The tutorial covers everything from list creation to the insertion & calculation of values in multi-record tables in letters. Do read the tutorial before trying to use the mailmerge document included with it.

    The field coding for this is complex. However, since the tutorial document includes working field codes for all of its examples, most of the hard work has already been done for you - you should be able to do little more than copy/paste the relevant field codes into your own mailmerge main document, substitute/insert your own field names and adjust the formatting to get the results you desire. For some worked examples, see the attachments to the posts at:
    http://www.msofficeforums.com/mail-m...html#post23345
    http://www.msofficeforums.com/mail-m...html#post30327

    Another option would be to use a DATABASE field in a normal ‘letter’ mailmerge main document and a macro to drive the process. An example of this approach can be found at: http://answers.microsoft.com/en-us/o...1-1996c14dca5d
    The DATABASE field can even be used without recourse to a mailmerge. An example of such usage can be found at: http://www.msofficeforums.com/mail-m...html#post67097

    Alternatively, you may want to try one of the Many-to-One Mail Merge add-ins, from:
    Graham Mayor at http://www.gmayor.com/ManyToOne.htm; or
    Doug Robbins at http://bit.ly/1hduSCB
    Last edited by macropod; 11-22-2019 at 05:07 AM.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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