Solved

Run macro when visio closes

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The Question Several times in recent years, someone has posted a question at EE asking whether they could display the Windows directory structure – folders and subfolders – using Visio. When one person specifically asked about displaying directory …
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

20 Experts available now in Live!

Get 1:1 Help Now