Solved

Run macro when visio closes

Posted on 2009-06-30
5
720 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
The ability to add structure to Visio diagrams using containers, lists and callouts is one of my favorite features in Visio 2010. In this article I’ll describe a mashup of containers and lists that meet a real-world need. Prior to reading this ar…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

803 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