WD: Value Out of Range Error Using WordBasic BookmarkName$ |
Q173811
When you use the WordBasic function BookmarkName$(), you may receive the following error message:
Value out of range
This error message occurs when you attempt to use the BookmarkName$() function with the number of a hidden bookmark.
WordBasic (Word 6.x and 7.x):
For example, the following macro returns a "Value out of range" error
message when the active document contains a Table of Contents:
Sub MAIN
x = SelInfo(29)
BK$ = BookmarkName$(x)' <-- The error occurs at this line.
MsgBox BK$
End Sub
NOTE: You will receive the same error in Word 97 if you convert this macro
to Visual Basic for Applications, as follows:
Sub MAIN()
x = WordBasic.SelInfo(29)
BK$ = WordBasic.BookmarkName$(x)' <-- The error occurs at this line.
MsgBox BK$
End Sub
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please see the following page on the World Wide Web:
http://www.microsoft.com/partner/referral/For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://support.microsoft.com/directory/overview.aspTo work around this problem, you can trap the error as shown in the following macro example.
Sub MAIN
' Set an Error trap for the hidden bookmark.
On Error Goto hiddenbmkerror
' Display the name of the bookmark for the selected text.
MsgBox BookmarkName$(SelInfo(29))
hiddenbmkerror: ' This line must be left-aligned!
' If "Value Out of Range" error...
If err = 512 Then
' then display a message indicating the cause of the error.
MsgBox "Cannot return hidden Bookmark Names."
Else
' If the error number is not 512, display the error.
Error Err
End If
End Sub
Visual Basic for Applications (Word 97):
MsgBox ActiveDocument.Bookmarks(Selection.BookmarkID).Name
Argument Explanation
---------------------------------------------------------------------
Count The number of the bookmark, from 1 to the total number of
bookmarks defined for the active document. You can obtain
the total using CountBookmarks(). The order of the bookmarks
in the document determines the order of bookmark names.
You must specify Count; otherwise, the function
returns an error. For example, a$ = BookmarkName$()
generates an error. For more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:
Q163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: 8.0 8.00 vba
Keywords : kberrmsg kbmacro kbprg kbdtacode kbmacroexample word8 winword word6 word7
Issue type : kbprb
Technology : kbWordSearch kbWordWSearch
|
Last Reviewed: December 29, 2000 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |