VBA code for saving a file with a reference nr

Started by aee74, August 09, 2018, 01:48:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aee74

Hello,
I have a visio template in which I have a reference nr field (Custom formula =DOCLASTEDIT() in format {{MyyHHmm}})
Now I want to create a vba code that will save the file with a chosen file name and the reference nr.

so the output would be something like test8181545.vcdx

Can anyone help me with this. Or is there a better way to do this.

wapperdude

#1
See this for programmatically saving a file:  https://docs.microsoft.com/en-us/visualstudio/vsto/how-to-programmatically-save-visio-documents

As an observation, I would change the timestamp order to year,month, hour, minutes.  The Windows naming takes a left right, alpha/numeric precedence.  Thus, your files would be naturally sorted by name, then year, month, etc.  Just a suggestion.

Hope the link helps.

Wapperdude
Visio 2019 Pro

aee74

Quote from: wapperdude on August 10, 2018, 01:32:40 AM
See this for programmatically saving a file:  https://docs.microsoft.com/en-us/visualstudio/vsto/how-to-programmatically-save-visio-documents

As an observation, I would change the timestamp order to year,month, hour, minutes.  The Windows naming takes a left right, alpha/numeric precedence.  Thus, your files would be naturally sorted by name, then year, month, etc.  Just a suggestion.

Hope the link helps.

Wapperdude

Is it possible to use a simple function like:

Private Sub Document_BeforeDocumentClose(ByVal doc As IVDocument)


    ThisDocument.SaveAs "path\filename .vsd"


End Sub


where the "path\filename .vcd" should be something like "path\file()+DOCLASTEDIT().vsd"
the filename was created the first time the vsd was saved. What I need is a simple way to add a reference nr to my filename.