|
|
|
|
|
|
Word
|
Check for Bookmark Name With Custom Right-Click Menu
|
|
Ease of Use
|
Easy
|
Version tested with
|
2000, 2003
|
Submitted by:
|
MOS MASTER
|
Description:
|
Programmatically add button to right click menu. The button code shows all bookmark names in current selection.
|
Discussion:
|
An easy way to get the bookmark names in the selection via the context menu.
The idea is to provide a button on witch you can attach a procedure you will often make use of.
|
Code:
|
instructions for use
|
Option Explicit
Private Sub Document_Open()
Dim oButton As Office.CommandBarControl
CustomizationContext = NormalTemplate
Set oButton = Application.CommandBars("Text").Controls.Add
With oButton
.Caption = "Show Bookmarks"
.FaceId = 351
.Style = msoButtonIconAndCaption
.OnAction = "ThisDocument.ShowBookmarksInSelection"
.BeginGroup = True
End With
Set oButton = Nothing
End Sub
Private Sub Document_Close()
On Error Resume Next
CustomizationContext = NormalTemplate
Application.CommandBars("Text").Controls("Show Bookmarks").Delete
End Sub
Sub ShowBookmarksInSelection()
Dim oRange As Word.Range
Dim oBm As Word.Bookmark
Dim sMsg As String
Set oRange = Selection.Range
For Each oBm In oRange.Bookmarks
sMsg = sMsg & oBm.Name & vbCrLf
Next
If sMsg <> "" Then
MsgBox sMsg
End If
Set oRange = Nothing
End Sub
|
How to use:
|
- Open your Word document.
- Press Alt + F11 to open the VBE window.
- Double click "ThisDocument" on the project explorer. (press CTRL+R to view)
- Paste the code there in the window at right. (F7)
- Close VBE (Alt + Q or press the X in the top right hand corner).
- Save the file.
|
Test the code:
|
- Double click the file to open and the button is added to the context menu
- Select some text that?s bookmarked and click button ?Show Bookmarks? on the context menu
- A message box will show you all the bookmark names. (in selection)
|
Sample File:
|
Add button to (right-click) context menu.zip 8.77KB
|
Approved by mdmackillop
|
This entry has been viewed 82 times.
|
|