VBA for Microsoft Word - Searching, Selecting and Going to Bookmarks

KyleJackMorrison

Board Regular
Joined
Dec 3, 2013
Messages
107
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Hello,

I understand this is for gurus on VBA for excel, however i would really like help on this code ive got.

I have a UserForm which finds all bookmarks that i've put in on my document. This is a code i got off of the internet, and there is a Compile Error which i can't solve.

here is a dropbox link to the document:
HTML:
https://www.dropbox.com/s/qkr1fqy55p9p9ii/testing%20%5B493173%5D.docm?dl=0

here is the code:
Code:
Private Sub UserForm_Click()
Option Explicit
Private m_gotoInProgress As Boolean
' Load bookmarks on bookmarks selection form activation.
Private Sub UserForm_Activate()
Dim bmk As Bookmark
    lstBookmarks.Clear
    For Each bmk In ActiveDocument.Bookmarks
       lstBookmarks.AddItem (bmk.Name)
    Next bmk
    txtBookmarkNames.SetFocus
End Sub


' Select bookmark using quick selection textbox.
Private Sub txtBookmarkNames_Change()
    If (Not isNullOrEmpty(txtBookmarkNames.Text)) Then
        Dim bmkName As Variant
        Dim listIndex As Integer
        listIndex = -1
        For Each bmkName In lstBookmarks.List
           listIndex = listIndex + 1
           If (Len(bmkName) >= Len(txtBookmarkNames.Text)) Then
              If (UCase(Left(bmkName, Len(txtBookmarkNames.Text))) = UCase(txtBookmarkNames.Text)) Then
                 lstBookmarks.Selected(listIndex) = True
                Exit For
              End If
           End If
        Next bmkName
    End If
End Sub


' Check if a string is null or empty.
Private Function isNullOrEmpty(ByVal s As String)
    If (IsNull(s)) Then
        isNullOrEmpty = True
    ElseIf (Len(s) = 0) Then
        isNullOrEmpty = True
    End If
End Function


' Go to selected bookmark.
Private Sub cmdGoto_Click()
    On Error GoTo cmdGoTo_Click_Finally
    If (IsNull(lstBookmarks.listIndex)) Then
        MsgBox "There is no any bookmarks selected", vbExclamation + vbOKOnly, "Warning"
        Return
    End If
    Selection.GoTo What:=wdGoToBookmarks, Name:=lstBookmarks.List(lstBookmarks.listIndex)
[COLOR=#ff0000]    cmdGoTo_Click_Finally[/COLOR]
     If (m_gotoInProgress) Then
         m_gotoInProgress = False
         DoEvents
         txtBookmarkNames.SetFocus
    End If
End Sub

The cmdGoTo_Click_Finally code pops up with an Compile error.

Any help will be much appreciated.

Kyle
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi Kyle

To me it looks like cmdGoTo_Click_Finally is for your error handling just add a : (colon) to the end of the line you have highlighted in red.

Regards

Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,353
Messages
6,124,462
Members
449,163
Latest member
kshealy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top