Consulting

Results 1 to 5 of 5

Thread: Bookmarks from source document to target document

  1. #1
    VBAX Regular
    Joined
    May 2015
    Posts
    44
    Location

    Bookmarks from source document to target document

    Hi guys,

    I have a word document that contains multiple sections of text which are bookmarked ("Source Document").

    I need code that will open up another template word document ("Target Document") and paste the bookmarked text from the Source Document into the places that I have bookmarks in the Target Document. Any ideas?

    E.g.

    The first bookmark in the Source Document contains an individual's name. I need the contents of the bookmark (i.e. the name) to be inserted into the name bookmark in the Target Document. Subsequently I will then want to do the same with all of the other bookmarks in the Source Document (e.g. date of birth, address, start date, end date etc. etc.)


    The bookmarks in the Source Document are also basically name things like "bmname", "bmdob", "bmaddress" and the bookmarks in the Source Document bookmarks have the same or similar bookmark names.

    Many thanks

    AJHEZ

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    You have to start writing code e.g.

    Sub MyFirstMacro()

    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Regular
    Joined
    May 2015
    Posts
    44
    Location
    That was a little mean-spirited...

    Apologies if I came across as a little needy in my post - funnily enough I've tried to do something like this before and looking back at my posts it was actually you that offered some really fantastic and useful advice. On that occasion I started my message including my own 'MyFirstMacro' code. I'll take a look at that again.

    Cheers,
    AJHEZ

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    I suppose that depending on one's perspective my "You have to start writing code ..." was a little mean spirited or more useful advise.

    The point is that I (and I think most other regulars here) are more than willing to help you learn but don't see this forum as a free code writing service.
    Last edited by gmaxey; 05-30-2017 at 08:14 AM.
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    There are at least two approaches that you could adopt

    1. Use the source document as a template and create a new document from it. It will thus be already populated.
    2. Open both documents. Read the values from the bookmark ranges and write them to the new bookmarks. In the Useful VBA functions on my web site you will find the FillBM function which will fill a named bookmark with the value applied, and can be called multiple times.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

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