Results 1 to 3 of 3

Thread: VBA WORD: readings words setting bookmarks ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    71

    VBA WORD: readings words setting bookmarks ?

    Hello, this is my very first VB program and i have a word document that contains certan pre-marked items, ie i put these a "<:" ":>" symbols around the items, and i'm trying to create a program that will recognize these symbols and automatically create a bookmark with what is in between these symbols.

    The code seems to put the correct name in the bookmark list, but when i try to manually create a hyperlink to that bookmark, it doesn't jump to that bookmark location as expected and i realize that i probably need to use some special word(method) to capture the symbol and word's actual location and then apply the bookmark to that exact location does that sound like what i need please?

    Any pointers would be appreciated! Thanks very much!

    Sub ReadWord
    Dim SingleWord As String
    Dim pre3 As String
    Dim pre2 As String
    Dim pre1 As String

    For Each aword In ActiveDocument.Words
    ' Range wr = aword.Item

    SingleWord = Trim(LCase(aword))

    pre3 = pre2
    pre2 = pre1
    pre1 = aword

    'MsgBox (" 3/" + pre3 + " 2/" + pre2 + " 1/" + pre1)

    If pre3 = "<:" And pre1 = ":>" Then
    'ActiveDocument.Bookmarks.Add pre2
    With ActiveDocument.Bookmarks
    .Add Range:=Selection.Range, Name:=pre2
    End With
    End If

    Next aword

    End Sub

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    71

    Re: VBA WORD: readings words setting bookmarks ?

    Ok i think this works okay if i type it in like this:

    ...Name:="test name", but not when i use a variable name, pre2 as so:

    ...Name:=pre2

    So i quess my new question is how to use a variable name, pre2, instead of a
    literal name, "test_name" as a way to assign a name to the Name variable.

    Thanks again!
    BobK

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    71

    Re: VBA WORD: readings words setting bookmarks ?

    ok got it, thanks for reviewing!

    With ActiveDocument.Bookmarks
    .Add pre2, Selection.Range
    End With

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