Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jan 2003
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    REF Field and Bookmarks (Word 2000)

    We have a quick macro that will insert a REF field at the insertion point in a document and ask the user for the bookmark name to which the REF field will refer. However, users cannot remember all the bookmark names in the document (there are many!) and would like a list displayed so that they can select the bookmark from the list and then run the macro. I tried to use the sample With statement shown below [Dialogs(wdDialogInsertBookmark)], but I don't know how to get the selection into the variable. Could someone please advise me on code to make such a procedure work. Many thanks...Mary

    Sub InsertREFField()
    Dim strBookmark As String
    strBookmark = InputBox("Enter the bookmark name")
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
    "REF " & strBookmark, PreserveFormatting:=False
    End Sub

    SAMPLE:
    With Dialogs(wdDialogInsertBookmark)
    .Name = "*.*"
    .Show
    End With

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: REF Field and Bookmarks (Word 2000)

    Some dialogs do not automate well. In particular, dialogs that stay open and let you do multiple things seem not to pass the expected values back to VBA. In the case of the Insert Bookmark's GoTo button (or the Go To dialog's Bookmarks option), the dialog does not close, so this probably won't work for you. (I haven't tried to code it, so I could be wrong!)

    Once upon a time I posted a macro (see <post#=165392>post 165392</post#>) that put all of the bookmarks into a drop-down list on a custom toolbar. That macro shows how to retrieve the names out of the document's bookmarks collection, and when the user chooses a bookmark, the insertion point jumps there. A toolbar may not be the best solution in your case because it will not integrate into your existing code very well -- it was desiged to be a complete solution from the toolbar itself, giving users a one-click operation, and could be adapted so that users position your insertion point and use the drop-down to insert the REF field. If that doesn't work for your application, then you probably would need to move on to actually displaying your own list in a VBA UserForm. A bigger project, but much slicker than automating a Word dialog and easier to explain than the toolbar. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  3. #3
    2 Star Lounger
    Join Date
    Jan 2003
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: REF Field and Bookmarks (Word 2000)

    Many thanks for your quick response. I think your macro could work if we could modify it to insert the REF field at the insertion point and then instead of going to the bookmark selected, make the selected bookmark the variable to include in the REF field. Could you please help me with the code to modify your macro? Many, many thanks...Mary

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: REF Field and Bookmarks (Word 2000)

    Mary, I added your code from your first post into a new little procedure, and linked the toolbar to that procedure. I also added a little check to see if the user might accidentally be replacing a selection that is bigger than an insertion point; hopefully that is more helpful to them than annoying. To try it out, copy a document that contains bookmarks (e.g., Save As to preserve your original), open the VBE (Alt+F11), and import the attached module. (First download and change the extension back from _bas.txt to .bas, then use File>Import to add it to your document.) Works?
    Attached Files Attached Files

  5. #5
    2 Star Lounger
    Join Date
    Jan 2003
    Posts
    187
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: REF Field and Bookmarks (Word 2000)

    Many, many thanks...your code works like a charm, and will certainly do the trick! I appreciate your help very much!...Mary

Posting Permissions

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