Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Frank - 05 Oct 2006 12:11 GMT
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
Greg Maxey - 05 Oct 2006 12:50 GMT
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.

> I have a on close event macro that adjust some tables in a word document when
> it is closed for the first time.
[quoted text clipped - 6 lines]
>
> Frank Krogh
Tony Jollans - 05 Oct 2006 19:12 GMT
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

> I have a on close event macro that adjust some tables in a word document when
> it is closed for the first time.
[quoted text clipped - 6 lines]
>
> Frank Krogh
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.