+ Reply to Thread
Results 1 to 9 of 9

How to retrieve value of the bookmarks from the word document

  1. #1
    Registered User
    Join Date
    02-24-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    76

    How to retrieve value of the bookmarks from the word document

    I have written a code to delete the sentence range which has its bookmark value as empty.
    Please Login or Register  to view this content.
    But the problem is that the sentence with the empty bookmark text is getting deleted. What i really want is to delete the bookmarks and its corresponding sentence if the bookmark value is empty. For example, the bookmark text is "XXX" but the data populated from excel cell to bookmark is empty cell. So i need to delete that bookmark and its sentence. the above code deletes the bookmark if there is no text. I tried working over this for several hours but of no improvement. Please help.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: How to retrieve value of the bookmarks from the word document

    Then you'll need to test the excel cell value for nothing and delete the corresponding bookmark.

    Not tested.
    Please Login or Register  to view this content.
    Or you could setup your document with the entire sentence in a bookmark, then have a bookmark within that to change the value. Then you could just delete the sentence bookmark without having to expand the value bookmark.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    02-24-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: How to retrieve value of the bookmarks from the word document

    Ok I find the A is integer that starts from lastrow to 2 step wise. But I get Byref argument type mismatch error. And it points to red line that i have highlighted.
    Please Login or Register  to view this content.
    Last edited by mvneema; 03-17-2014 at 04:54 PM.

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: How to retrieve value of the bookmarks from the word document

    Is A greater than 1?

    Or is lastrow > 2.

    This code is really incomplete. You'll need to 'flesh it out'.

    If you need help with that, provide a few details about the data in Excel. Where the data located, etc. Is it all in a column, or spread out around the sheet?????

  5. #5
    Registered User
    Join Date
    02-24-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: How to retrieve value of the bookmarks from the word document

    Ok. I still couldnt find a solution for that. I have attached a sample excel sheet and its word document template. the data is located in "data" sheet with row 1 as column number, row 2 with bookmark name,row 3 column name and from row 4 onward there is data. the "setup" has the column number, bookmark name and description of bookmarks. the third sheet is "codeinfo" has the template name and destination folder where the reports are to be saved. Please help.
    Attached Files Attached Files
    Last edited by mvneema; 03-18-2014 at 08:24 AM.

  6. #6
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: How to retrieve value of the bookmarks from the word document

    OK, so you've discovered Word's dirty little bookmark secret. When you insert text using the bookmark, it replaces the text AND THE BOOKMARK. So the bookmark gets deleted. Then, when you iterate the newly created document for bookmarks, there isn't any. That's why the code isn't working. (Because the code works in Word before the bookmark replacement.) You can read about the workaround here.

    Sorry, that I can't spend more time on this, but I've been called out of town and don't know if I'll get back to it soon.

    I still think you should create blank bookmarks and add the entire phrase in the bookmark instead of the current setup. Then you only have to 'touch' the bookmark once. So, instead of replacing the XXX with For, have an empty Bookmark named VoteNxt, and replace it with Vote for next year: For. If the value of the bookmark is empty (in the excel sheet), then just skip it.

    Good luck.

  7. #7
    Registered User
    Join Date
    02-24-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: How to retrieve value of the bookmarks from the word document

    hi Tinbendr, nice to hear from you. As you have specified now I am trying to have the whole sentence as bookmarks so that if there is no value from excel I will just get a blank line. Thanks for the idea.
    Last edited by mvneema; 03-21-2014 at 12:58 PM.

  8. #8
    Registered User
    Join Date
    02-24-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: How to retrieve value of the bookmarks from the word document

    Hey Tinbendr, i tried your idea that has the whole statement to be bookmarked. Now I am trying to delete those extra pages after that blank statement. Can you provide me with an idea on doing this. My goal was to delete pages but I dont know how exactly to code. If you could be so kind enough to provide me with the links or any search sites?

  9. #9
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: How to retrieve value of the bookmarks from the word document

    It's very difficult to delete pages in Word. It's always better to start with less and add in. In Excel, everything is exact, but Word in fluid and moves around a lot, thus making it difficult to delete objects with any certainty.

    I have an attachment (fancy table) that I use in my work, but I don't need on every report. So I created an Attachment.doc and 'InsertFile' whenever I need the table. I had much more success adding a page than trying to delete the second page.

+ 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 code to delete the empty bookmarks in Word document
    By mvneema in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-18-2014, 08:29 AM
  2. retrieve excel contents to a word document
    By SathishKumar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-25-2013, 09:44 AM
  3. Add text to Existing Word Document if it Doesn't exist create Word Document
    By unstable81 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-10-2013, 12:15 AM
  4. Excel and Word Bookmarks
    By JFamilo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-14-2005, 01:05 AM
  5. exporting data to appear at Bookmarks in a Word Document
    By Dave Kilroy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-19-2005, 02:44 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