strange error message in Word 97 VB code window

L

Larry

This macro intercepts EditUndo and works in conjunction with two other
macros that enable me to undo an entire macro in one step using Ctrl+Z.
However, when I place cursor in BookMarkExists and press F1, I get the
following error message:

"Unexpected error 32811. Contact Microsoft Technical support."

Any ideas why this is happening?

Sub EditUndo()
' Catches Ctrl-Z. Loops EditUndo until previous macro is undone.
If ActiveDocument.Undo = False Then Exit Sub
While BookMarkExists("_InMacro_")
If ActiveDocument.Undo = False Then Exit Sub
Wend
End Sub
 
C

Cindy M -WordMVP-

Hi Larry,

Well.. BookmarkExists is not a built-in Word function. At least, not that
I'm aware. So, what does THIS function do? And where is it located?
This macro intercepts EditUndo and works in conjunction with two other
macros that enable me to undo an entire macro in one step using Ctrl+Z.
However, when I place cursor in BookMarkExists and press F1, I get the
following error message:

"Unexpected error 32811. Contact Microsoft Technical support."

Any ideas why this is happening?

Sub EditUndo()
' Catches Ctrl-Z. Loops EditUndo until previous macro is undone.
If ActiveDocument.Undo = False Then Exit Sub
While BookMarkExists("_InMacro_")
If ActiveDocument.Undo = False Then Exit Sub
Wend
End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
L

Larry

Cindy,

BookmarkExists is part of this suite of macros, the purpose of which is
to change the functioning of EditUndo so that an entire macro can be
undone with a single Undo command. I keep this in its own module. Here
it is.

Option Explicit

Sub StartUndoSaver()

' NOTE: These macros were provided by Roemer Lievaart
' at (e-mail address removed). It enables Ctrl+Z to undo an
' entire macro in one step. It was on a web page.
'This line must be put at beginning of the
' macro being tested:
'Application.Run "StartUndoSaver"
' And this line must be put at the end of the
' macro being tested:
' Application.Run "EndUndoSaver"

On Error Resume Next
ActiveDocument.Bookmarks.Add "_InMacro_"
On Error GoTo 0
End Sub

Sub EndUndoSaver()
On Error Resume Next
ActiveDocument.Bookmarks("_InMacro_").Delete
On Error GoTo 0
End Sub

Sub EditUndo()
' Catches Ctrl-Z, both for this special purpose and all-round.

' This first line by itself performs the same task as running
' EditUndo once. But if a macro containing EndUndoSaver was run
' just before this is run, that the line also has the effect of
' undoing the deletion of the bookmark "InMacro," meaning that
' "InMacro will now exist.

If ActiveDocument.Undo = False Then Exit Sub

' Now a loop begins which keeps repeating EditUndo as long as
' "InMacro" bookmark exists, i.e., until it has undone the entire
' macro which began with creating the "InMacro bookmark. Ingenious!
While BookMarkExists("_InMacro_")
If ActiveDocument.Undo = False Then Exit Sub
Wend
End Sub

Sub EditRedo()
' Catches Ctrl-Y

If ActiveDocument.Redo = False Then Exit Sub
While BookMarkExists("_InMacro_")
If ActiveDocument.Redo = False Then Exit Sub
Wend
End Sub

Private Function BookMarkExists(Name As String) As Boolean
On Error Resume Next
BookMarkExists = Len(ActiveDocument.Bookmarks(Name).Name) > -1
On Error GoTo 0
End Function
 
D

Doug Robbins - Word MVP

Hi Larry,

You are missing a period between Bookmarks and Exists. From the VB Help
file

If ActiveDocument.Bookmarks.Exists("start") = True Then
ActiveDocument.Bookmarks("start").Delete
End If

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
C

Cindy M -WordMVP-

Hi Larry,
BookmarkExists is part of this suite of macros, the purpose of which is
to change the functioning of EditUndo so that an entire macro can be
undone with a single Undo command. I keep this in its own module. Here
it is.
Hmmm, I'm not to thrilled with all the end runs around the error messages.
That probably explains why you're not getting an error message that's more
accurate as to the real problem.

Obviously, the person who wrote the original macro didn't realize that
Word 97 and later versions came with a built-in function to test the
existence of a bookmark. I'd try changing the code to use that, roughly:

Sub EditUndo()
' Catches Ctrl-Z. Loops EditUndo until previous macro is undone.
If ActiveDocument.Undo = False Then Exit Sub
Do While ActiveDocument.Bookmarks.Exists("_InMacro_")
If ActiveDocument.Undo = False Then Exit Sub
Loop
End Sub

(While...Wend is old programming style, and should be discarded as
opportunity permits (like, when you're editing the code, anyway).)

If you don't want to make this change for some reason, then comment out
all the On Error Resume Next lines and see what kinds of errors get thrown
up.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
L

Larry

Thanks, Cindy, I'll try this out.

Larry




Cindy M -WordMVP- said:
Hi Larry,

Hmmm, I'm not to thrilled with all the end runs around the error messages.
That probably explains why you're not getting an error message that's more
accurate as to the real problem.

Obviously, the person who wrote the original macro didn't realize that
Word 97 and later versions came with a built-in function to test the
existence of a bookmark. I'd try changing the code to use that, roughly:

Sub EditUndo()
' Catches Ctrl-Z. Loops EditUndo until previous macro is undone.
If ActiveDocument.Undo = False Then Exit Sub
Do While ActiveDocument.Bookmarks.Exists("_InMacro_")
If ActiveDocument.Undo = False Then Exit Sub
Loop
End Sub

(While...Wend is old programming style, and should be discarded as
opportunity permits (like, when you're editing the code, anyway).)

If you don't want to make this change for some reason, then comment out
all the On Error Resume Next lines and see what kinds of errors get thrown
up.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top