Run Time Error 5825 - Object Deleted



I have some VBA macro code below for Word 2003 (not the entire subroutine).
The ActiveDocument.Variable("Document Number") is defined earlier in another
subroutine, and the user is prompted for it, among other document variables.
Unfortunately, if the user leaves it blank, the macro below gives the Run
Time Error 5825; debug shows that processing stops at the line

If VProcNum = ""

VProcNum is not NULL, ISERROR of ISEMPTY. How can I fix the macro and
prevent getting this error message?


here's the macro...

Sub ManualTitle()
' ManualTitle Macro
Dim VProcNum
' Create variable for Procedure Number; if it is empty, warn the user
Set VProcNum = ActiveDocument.Variables("Document Number")
If VProcNum = "" Then
Style = vbOKOnly + vbInformation + vbDefaultButton1
Response = MsgBox("Without a Document Number, some header variables
will not be populated ", Style, "No Document Number")
End If

Malcolm Smith

The problem is that you're mixing up types.

ActiveDocument.Variables("Document Number")

will return a Variable object. You are testing for a string. I also
note that you haven't defined what sort of type VProcNum is in your Dim

Once you've set them all to the same type then you could do:

If VProcNum is Nothing then

But you'll have to make sure that the Document Variable does exist first.
I would write a small function which goes through the document's Variables
and then checks to see if the variable exists.

- Malc

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