Using File>Save As to trigger a script?

Started by JasonB_SE, January 10, 2023, 06:10:34 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JasonB_SE

I work as a Sales Engineer with a large service provider and am working on a standardized visio template to be used at least in my region if not nationwide.  To do this, I have to do more than just put lipstick on the pig so to speak.  I have to build some functionality into the .vsdx file.

I have the following code working to update some container values on a visio diagram. 

Private Sub updatedSaveAs()
'this macro updates filename, version, and last modied date on the background page, and then creates and updates the filename by concatenating certain values within this document

'activate background page
ActiveWindow.Page = ActiveDocument.Pages("Background")

Dim myDate As String
Dim myVer As Single
Dim myFilename As String
myDate = ActivePage.Shapes("myModifyDate").Characters
myVer = ActivePage.Shapes("myVersion").Text + 0.1
myNewFilename = ActivePage.Shapes("myProjectName").Text & "_Ver " & myVer & "_" & myDate & ".vsdx"
ActivePage.Shapes("myVersion").Text = myVer
ActivePage.Shapes("myFilename").Text = myNewFilename

'go back to drawing page
ActiveWindow.Page = ActiveDocument.Pages("Drawing")

End Sub


This code drives values to the background image that holds information about the drawing without requiring the user to manually change the values.  I also have the date modified field set up a field to update the date/time any time the document is edited in any way. 

I want to possibly utilize the file save as to trigger the above script to update the remainder of the fields just before the file is saved. 

Ideally, I'd really like to save simultaneously both a vsdx and PDF in a folder that the user selects...

These last two items are where i'm stuck.  Any ideas would be greatly appreciated.

Paul Herber

One thing you will need to do is to rename your document as .vsdm to enable macros.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Yacine

In the "ThisDocument" module of your file choose first "Document" from the left pulldown, then the according event from the right one.
Yacine