Results 1 to 2 of 2

Thread: Export MSWord Bookmarks & Selected Text to Excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    1

    Export MSWord Bookmarks & Selected Text to Excel

    I've recently been tasked with document consolidation and standardization at my organization for one of our clients. The client is government and thus standardizes nothing and has 80 bookmarks per document. They want all of the bookmarks and their selected text into an excel document.

    The bookmark names aren't standardized so I can't use a lot of the examples here. I know you can do bookmark retrieval by numbers. i.e. - Selection.Bookmarks(1).Name - will give me the name of bookmark #1 and summarily Selection.Bookmark(1).Select will give me all of the text inside the bookmark.

    What I'd l ike to be able to do is (even if 1 document at a time), is run a script that dumps all of the bookmark names and their associated text into an excel spreadsheet. I really have no desire to do this manually >.<

    Thanks in advance for any assistance you can offer.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Export MSWord Bookmarks & Selected Text to Excel

    you can try like this
    vb Code:
    1. For Each b In ActiveDocument.Bookmarks
    2.     MsgBox b.Name
    3.     MsgBox b.Range.Text
    4. Next
    if this gives the correct results, instead of the messageboxes, you can insert the strings into excel cells,
    you can then automate to read every document in a folder (including subfolders if required), to add to the end of the worksheet, or to add a worksheet for every document, or whatever, depending on your requirements
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width