?
Solved

Run macro when visio closes

Posted on 2009-06-30
5
Medium Priority
?
748 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Have you ever created a custom Visio stencil – a collection of your own unique master shapes – and then created a drawing by dragging masters onto the drawing page? Have you then made changes to the stencil master and wondered why the shapes on the …
David Parker’s latest book, Microsoft Visio 2010: Business Process Diagramming and Validation, will give you the tools to turn flowcharts and other business diagrams into valuable, data-driven corporate assets. Armed with the knowledge you’ll gain f…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 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