Solved

Run macro when visio closes

Posted on 2009-06-30
5
716 Views
Last Modified: 2012-08-14
I need to run a macro when closing visio, and I can't seem to find the appropriate documentation to get me there.  Any help would be appreciated.
0
Comment
Question by:WINAIRMVS
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:oldviking
ID: 24749738
I hope this will bring you a bit further:

http://msdn.microsoft.com/en-us/library/ms427232.aspx
0
 
LVL 2

Expert Comment

by:ryrasmussen
ID: 24751949
If you are working with a specific file, you can add a "Before Document Close" event.
Enter the VBA editor, find the "This document" section in the project explorer, and select the BeforeDocumentClose event in the dropdown to the far right.
0
 

Author Comment

by:WINAIRMVS
ID: 24755024
I added the code to "This Document" which did not act on the closing of the document.
Private Sub BeforeDocumentClose()

 nameofmacroIwanttorun

end

Open in new window

0
 
LVL 4

Accepted Solution

by:
oldviking earned 500 total points
ID: 24755711
I tried this myself, and it worked fine with Visio 2007.

But please check that you have enabled macros under Tools, Trust center, Macro settings, and restarted Visio afterwards.
Private Sub Document_BeforeDocumentClose(ByVal doc As IVDocument)
 

Dim Msg, Style, Title, Help, Ctxt, Response, MyString

Msg = "Do you want to continue ?"    ' Define message.

Style = vbYesNo + vbCritical + vbDefaultButton2    ' Define buttons.

Title = "MsgBox Demonstration"    ' Define title.

Help = "DEMO.HLP"    ' Define Help file.

Ctxt = 1000    ' Define topic

        ' context.

        ' Display message.

Response = MsgBox(Msg, Style, Title, Help, Ctxt)

If Response = vbYes Then    ' User chose Yes.

    MyString = "Yes"    ' Perform some action.

Else    ' User chose No.

    MyString = "No"    ' Perform some action.

End If
 

    

End Sub

Open in new window

0
 

Author Closing Comment

by:WINAIRMVS
ID: 31598495
Answer was what I needed.  There was some extra code that wasn't necessary for what I was looking for, but otherwise great answer!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Periodically someone asks me whether there’s a way to automatically convert all of the pages in a Visio drawing to PowerPoint slides. There have even been a few times when I’ve wanted to do that myself but I never really had enough incentive to figu…
Book Review: Using Microsoft Visio 2010 by Chris Roth   Disclaimer: The author of Using Visio 2010 is a friend and fellow Visio MVP. Whether you’re new to Visio or are upgrading to Visio 2010 from a previous version, you will find a lot to like…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now