Consulting

Results 1 to 8 of 8

Thread: How to insert a bookmark in a table

  1. #1
    VBAX Newbie
    Joined
    Jan 2024
    Posts
    3
    Location

    How to insert a bookmark in a table

    Hi there,

    I'm trying to insert a previosly defined Bookmark in a specific Cell in the Table of my Header by using VBA.

    here's what im working with:

    ActiveDocument.Sections(2).Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(3, 4).Range.InsertCrossReference ReferenceType:="Textmarke", ReferenceKind:=wdContentText, ReferenceItem:="Date", InsertAsHyperlink:=True
    Strangely this command adds the Reference at the Cell 1,3 and deletes the content of Cell 3,4.

    First sreenshot shows the wanted result. The second shows what the macro is doing.

    What am I doing wrong?
    Attached Images Attached Images

  2. #2
    VBAX Regular
    Joined
    Jan 2022
    Posts
    16
    Location
    Hi! I think the mistake is because of the merged cells in column 3. The cell that is supposed to be (1,3) is actually (3,4). Try replacing (1,3) with (3,4) in your code and the problem will go.
    Last edited by Vladimir; 01-10-2024 at 09:13 AM.

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Welcome to VBAX anhaase. Not sure I've ever seen a table within a header before... Perhaps I have but never recognised it as such.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    VBAX Newbie
    Joined
    Jan 2024
    Posts
    3
    Location
    Thanks for your Answer. I also thought about that, but I tried every combination of column and row, but the macro keeps ignoring the Column. it always ends up filling the first column.

  5. #5
    VBAX Regular
    Joined
    Jan 2022
    Posts
    16
    Location
    Frankly, I've never seen tables in headers either. Anyway, this code:
    selection.range.Tables(1).cell(3, 4).range = "Test"
    works properly. If not, it would be nice to see your table. Maybe, it is merged/split differently from mine.

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    According to this it's more than possible to have a table within a header. https://answers.microsoft.com/en-us/...2-6f7434b78f89
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Greg Maxey makes a good fist of inserting text with at or in a Bookmark. Particularly the point about vba destroying a Bookmark. Have a read here to see if this helps.https://gregmaxey.com/word_tip_pages..._bookmark.html.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  8. #8
    VBAX Newbie
    Joined
    Jan 2024
    Posts
    3
    Location
    Yes, Text works. I'm already using that command to enter Text in the footer:

    ActiveDocument.Sections(SecNr).Footers(wdHeaderFooterPrimary).Range.Tables( 1).Cell(row, col).Range.InsertAfter Text:=".E"

    Unfortunalty I don't know how to use the this structure to insert a bookmark.

    I attached my word file in case you guys want to try.
    https://easyupload.io/lsi02f

Posting Permissions

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