G
Greg
Hi All,
Yesterday I was helping another user crate a macro to
toggle from any font to "symbol" font and then toggle back
to the original font. The following works, but if the
initial font is "symbol" an error "Run time error 5825.
The object has been deleted." is generated. I understand
why the error is being generated but I can't figure out a
way to prevent the error or mask the error. I have tried
all kinds of On error Goto, On error Resume,
isObjectValid, .Exists, but nothing seems to work.
I am looking for a means to interupt (mask) the error
message with a more pleasing message something like "The
first use of this macro in the current document must be
initiated with a font other than symbol." Any help and
critique of the code below is welcome.
Sub ToggleFromAnyFontToSymbolandBack()
'Macro created July 25, 2004 by Gregory K. Maxey
If Selection.Font.Name <> "Symbol" Then
'Save current font name to a docvariable
ActiveDocument.Variables("OldFont").Value =
Selection.Font.Name
End If
With Selection.Font
If .Name <> "Symbol" Then
.Name = "Symbol"
Else: Selection.Font.Name = ActiveDocument.Variables
("OldFont").Value
End If
End With
End Sub
Yesterday I was helping another user crate a macro to
toggle from any font to "symbol" font and then toggle back
to the original font. The following works, but if the
initial font is "symbol" an error "Run time error 5825.
The object has been deleted." is generated. I understand
why the error is being generated but I can't figure out a
way to prevent the error or mask the error. I have tried
all kinds of On error Goto, On error Resume,
isObjectValid, .Exists, but nothing seems to work.
I am looking for a means to interupt (mask) the error
message with a more pleasing message something like "The
first use of this macro in the current document must be
initiated with a font other than symbol." Any help and
critique of the code below is welcome.
Sub ToggleFromAnyFontToSymbolandBack()
'Macro created July 25, 2004 by Gregory K. Maxey
If Selection.Font.Name <> "Symbol" Then
'Save current font name to a docvariable
ActiveDocument.Variables("OldFont").Value =
Selection.Font.Name
End If
With Selection.Font
If .Name <> "Symbol" Then
.Name = "Symbol"
Else: Selection.Font.Name = ActiveDocument.Variables
("OldFont").Value
End If
End With
End Sub