terminating macro if file already closed

Phenom
Phenom

I have a macro to assist users in placing drawing borders and filling in title blocks.

The macro works fine and I have checks in place to determine if the active draft file has changed when the user applies the data.

 

However, how should I handle the situation where the user has closed the draft file before closing the macro, or closed Solid Edge completely.

At the moment in the form closing event I call a 'Cleanup' routine that resets various parameters and releases all the objects.

If the user has already closed the file or Solid Edge do I still need to do this or do I simply close the form?

HP Z420 16GB RAM
Quadro K4000
ST7 MP10 on Windows 7 Pro 64.
3 REPLIES

Re: terminating macro if file already closed

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

You would want to attach to the Application.ApplicationEvents and listen for the BeforeQuit event. You'll also want to attach to the DraftDocument.DocumentEvents and listen for the BeforeClose event.

 

There are various ways to attach to these events, some better than others. I'm actually working on a blog post with GitHub samples demonstrating event handling. If you'll reply with your programming language, I'll get you a snippet to get you going.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: terminating macro if file already closed

Phenom
Phenom

Thanks Jason,

It was written in vb.net express 2008.

I could update it to 2013 if that's better as I have that installed now also.

HP Z420 16GB RAM
Quadro K4000
ST7 MP10 on Windows 7 Pro 64.

Re: terminating macro if file already closed

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

I'll likely work on the blog post over the weekend. If you want to get a head start, I just comitted the latest Visual Basic samples on GitHub. Download the zip, extract it and look at the Applications\EventHandling\EventHandling.sln.

Jason Newell
Applications Architect
www.jasonnewell.net