• Bookmarks in tables (Word VBA)

    • This topic has 2 replies, 2 voices, and was last updated 17 years ago.
    Author
    Topic
    #451589

    Hi folks – is there something special one needs to know to be able to code for adding a bookmark to a document? I need to be able to do so and all I did was record the creation of the bookmark and try to play it back – but everytime it says it doesn’t support this object – “object doesn’t support this property or method”. The entire macro just looks like this:

    Sub RecBlock()
        Selection.TypeParagraph
        Selection.MoveUp Unit:=wdLine, Count:=1
        With ActiveDocument.Bookmarks
            .Add Range:=Selection.Range, Name:="RECIPIENT_NAME"
            .DefaultSorting = wdSortByName
            .ShowHidden = False
        End With
        Selection.MoveDown Unit:=wdLine, Count:=1
        With ActiveDocument.Bookmarks
            .Add Range:=Selection.Range, Name:="RECIPIENT_ADDRESS"
            .DefaultSorting = wdSortByName
            .ShowHidden = False
        End With
    End Sub

    Exactly as recorded, but it just won’t play!

    Help! hairout

    Viewing 1 reply thread
    Author
    Replies
    • #1112117

      Hi Beryl,

      Your macro runs OK when I try it in Word 2003, whether the insertion point is inside a table or not. Where exactly does the error occur?

      BTW, the macro can be simplified to

      Sub RecBlock()
      Selection.TypeParagraph
      Selection.MoveUp
      ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:=”RECIPIENT_NAME”
      Selection.MoveDown
      ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:=”RECIPIENT_ADDRESS”
      End Sub

    • #1112119

      Hi Hans, thanks for this, and yes, I know about the simplification – I had done that myself, but I undid it when the macro kept crashing in an effort to find out why! The first two lines, to type a return and move back up to the line thus created work, then i get the error message, but it wouldn’t let me error check it!

      However, I have now tracked down the problem – a couple of lines of rogue code had crept in and were screwing the whole thing up!

      Sigh!

      Thanks anyway and sorry for wasting your time!!

    Viewing 1 reply thread
    Reply To: Bookmarks in tables (Word VBA)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: