Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need function for a macro that works when "x" is used to EXIT MSWord

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have very little experience with macros, and I am trying to write a macro that will delete files from a directory when Word is EXITED. I have figured out how to delete the files, and I have figured out how to change the File Exit command in Word so that when File Exit is used to EXIT Word, the designated files are deleted; however, when I EXIT Word using the &quot;x&quot; at the top right or when using <Ctrl+F4>, the designated files are not removed.

Is there a special function (not sure if &quot;function&quot; is the right word??) other than WordBasic.FileExit that will close Word and also run my desired functions within the macro?
 
Hi in this link you have a function to know if DOC is Open, put the function in a New Module.


When you run the Word Document set your Timer Interval like above

Me.TimerInterval = 1000

In OnTimer() Event put this lines of code. If the Function return true, the Document is Open so do nothing, else delete your files and set the timer to 0 zero

Private Sub Form_Timer()
If fIsDocFileOpen(&quot;YourDOC&quot;) = True Then
'Do Nothing
Else
'Run Your Delete Files Macro or Function
Me.TimerInterval = 0
End If
End Sub

Test if it work..Hope it helps.

Best Regards

---
JoaoTL
NOSPAM_mail@jtl.co.pt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top