I have a on close event macro that adjust some tables in a word document when
it is closed for the first time.

How do I delete or disable the macro during the first document closing?

Is it possible to delete the macro itself as the last command in the macro?

Regards

Frank Krogh

Re: VBA: How to make a word on close event macro run just once? by Greg

Greg
Thu Oct 05 06:50:09 CDT 2006

Frank,

You could set a document variable when the document is first closed and
then use it to determine if it has been closed previously and bypass
the remaing code:

Sub Document_Close()
On Error GoTo Handler
If ActiveDocument.Variables("Flag").Value = "Closed" Then
Exit Sub
Else
ActiveDocument.Variables("Flag").Value = "Closed"
MsgBox "Do your deed"
End If
Exit Sub
Handler:
ActiveDocument.Variables("Flag").Value = " "
Resume
End Sub

AFAIK you can't delete the macro in the manner you suggest.





Frank wrote:
> I have a on close event macro that adjust some tables in a word document when
> it is closed for the first time.
>
> How do I delete or disable the macro during the first document closing?
>
> Is it possible to delete the macro itself as the last command in the macro?
>
> Regards
>
> Frank Krogh


Re: How to make a word on close event macro run just once? by Tony

Tony
Thu Oct 05 13:12:01 CDT 2006

It _is_ possible (subject to the user allowing it in recent versions of
Word) to have self deleting code but it, in this case at least, it rather
begs the question as to how the code got into the document in the first
place.

--
Enjoy,
Tony

"Frank" <Frank@discussions.microsoft.com> wrote in message
news:607CDCE5-F820-4ACD-BD07-958CD8C8BE05@microsoft.com...
> I have a on close event macro that adjust some tables in a word document
when
> it is closed for the first time.
>
> How do I delete or disable the macro during the first document closing?
>
> Is it possible to delete the macro itself as the last command in the
macro?
>
> Regards
>
> Frank Krogh
>
>
>
>
>
>