KyleJackMorrison
Board Regular
- Joined
- Dec 3, 2013
- Messages
- 107
- Office Version
- 365
- 2021
- 2019
- Platform
- 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:
here is the code:
The cmdGoTo_Click_Finally code pops up with an Compile error.
Any help will be much appreciated.
Kyle
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