Results 1 to 15 of 15

Thread: How to move ALL Bookmarks from Word to Excel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Mike,

    At the top of your module you have this:

    On Error Resume Next
    This means that errors are ignored.

    Next, you get all your headings (bookmark names) by looping through all the bookmarks in the document - so far so good.

    Then, to get the bookmark values you loop using a counter for each bookmark in the document ..

    For x = 1 To WordDoc.Bookmarks.Count
        :
        :
    Next
    Still good! Now, inside the loop you use the Bookmark counter to reference FormFields - not so good, but becuase you ignore errors you don't see it.

    So you need to change the code inside the loop. Although I prefer to avoid them, an error trap is probably the easiest way to handle it in this case:

    For x = 1 To Me.Bookmarks.Count
        ' intRow is the file order number (each file will import on a new row)
        ' the x is the column - Essentially it'll cycle through all the bookmarks in the Word doc
        ActiveSheet.Cells(intRow + intFileNum, x + intCol - 1) = _
        WordDoc.FormFields(WordDoc.Bookmarks(x).Name).Result
        If Err.Number <> 0 Then
            Err.Clear
            ActiveSheet.Cells(intRow + intFileNum, x + intCol - 1) = _
            WordDoc.Bookmarks(x).Text
        End If
    Next
    Last edited by Aussiebear; 01-30-2025 at 11:32 AM.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.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
  •