+ Reply to Thread
Results 1 to 5 of 5

Smart way to create a standard Word Report with Excel data (Bookmarks?)

  1. #1
    Registered User
    Join Date
    05-26-2015
    Location
    Copenhagen
    MS-Off Ver
    2010
    Posts
    28

    Smart way to create a standard Word Report with Excel data (Bookmarks?)

    I have for quite some time now been looking into finding a way to create a standard Word Report that i will be using over and over, with data from various excel sheets. The layout of the report is predefined, however at different locations in the report
    i need figures/tabels/data/text to be changeable, based on what project i am working on.
    Initially i thought the "Paste Special, As link" feature could be the solution but after trying to make it work for quite some time, i've given up on that, as it keeps messing up my documents and breaking links for no apparent reason.

    So then someone suggested i tried using Bookmarks to define where i want to input text/figures to Excel.

    To some degree this is working in the sense that i have created a VBA modul that enables me to copy data from Excel to a specific point in the Word report (Predefined Bookmark) - However after the data is copied, i can't figure out a way to enable me to change the text that i now have in my word document, in case there is changes in the excel document. Essentially its a one-time transfer solution.

    Essentially i want to end up with something where i have a Word Document with a Macro button in it i can press, which will check for all the bookmarks i have defined, and update their values, based on the current values of the excel sheets that they are retrieved from.
    Can i do that with Bookmarks?

    Or should i try and go in a different direction?

    Thanks,
    Nicolai

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Smart way to create a standard Word Report with Excel data (Bookmarks?)

    If you can get your head around the way they work, Bookmarks are as good as any way to create documents

    Bookmarks in Word come in 2 flavours. 'Enclosing' and 'Placeholder', and they work differently.

    Please Login or Register  to view this content.
    If the Bookmark 'Bookmark_Name' is an Enclosing bookmark then the text will be inserted, but the Bookmark itself will be deleted.

    If it is a Placeholder bookmark then the bookmark will remain and the text added after.

    Either way you're left with a problem if you need to replace the text later. An Enclosed bookmark no longer exists, and you (generally) don't know how much text was inserted after a Placeholder bookmark.

    You can also insert text Before or After an Enclosing bookmark using
    Please Login or Register  to view this content.
    This will not delete an Enclosing bookmark but you still have the problem if you need to update later.

    To preserve your sanity, the best way to interact with bookmarks is to use Enclosing Bookmarks and a little sub that takes the Bookmark name and the Excel range to insert as parameters. This finds the bookmark, replaces the text and recreates the bookmark
    Please Login or Register  to view this content.
    To create an Enclosing bookmark, you need to highlight some existing text in the document and add the bookmark. Placeholder bookmarks are created if you insert a bookmark with no text selected.

    Placeholder bookmarks, are simpler to work with but only if it's a one time operation like creating a merged letter - if you need to update the document later, using code, then you must use Enclosing bookmarks - which means you must recreate the bookmark after updating it.

    The above is generally to replace words/sentences as text, it does not deal with tables - but that's reasonably easy, you just need to check in the procedure if there's more than 1 cell and handle it accordingly - but keeping this simple to start with. If you decide to go with it, I can extend the procedure for you or give pointers as to what you need to do.
    Last edited by cytop; 05-13-2016 at 03:22 AM.

  3. #3
    Registered User
    Join Date
    05-26-2015
    Location
    Copenhagen
    MS-Off Ver
    2010
    Posts
    28

    Re: Smart way to create a standard Word Report with Excel data (Bookmarks?)

    Thanks Cytop,

    it definitely looks interesting and might prove to be my solution. Initially I ll just try and get the copying of single excel cells into the word documents as bookmarks to work. Then I ll work with the tables and figures afterwards.

    I have made a code to copy a cell from excel into word (from a word VBA):

    Please Login or Register  to view this content.
    So essentially I open an excel document at a given path, I copy the value from cell A1 and the content of this cell is what I want to use in the bookmark named "Test1".
    Can you point me in the right direction in terms of combining this with the bookmark macro you linked?

    Thanks,
    Nic

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Smart way to create a standard Word Report with Excel data (Bookmarks?)

    A slight rewrite - my original ran in Excel and updated Word. Changed to run in Word and start Excel, load a workbook and update from that. It still assumes the ActiveDocument is being updated.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-26-2015
    Location
    Copenhagen
    MS-Off Ver
    2010
    Posts
    28

    Re: Smart way to create a standard Word Report with Excel data (Bookmarks?)

    Works like a charm!
    Thank you.

    I added:

    Please Login or Register  to view this content.
    at the end of the macro, aswell as adding to "This.Document" in my VBA project:

    Please Login or Register  to view this content.
    To ensure that Users cannot change my Bookmarks.

    Thanks alot for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA Transfer Data From Excel to Word and Keep Bookmarks in Word Documents
    By ShakJames in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-08-2015, 05:37 AM
  2. Replies: 5
    Last Post: 07-31-2014, 12:51 PM
  3. Populating data from excel into word bookmarks
    By pspiv0359 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-22-2013, 06:25 AM
  4. Create a report with data from cells, and standard text.
    By cristian.ene in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-03-2011, 07:05 AM
  5. Excel to Word passing data dynamically with bookmarks from Excel to Word
    By csekhar.apps in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-10-2010, 09:52 AM
  6. exporting Excel data to Word using Bookmarks
    By Dave Kilroy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-19-2005, 01:06 PM

Tags for this Thread

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