Search code examples
vbavisio

Visio macro to save a macro-free file


I have a series of complex charts to draw, so I have written a macro that takes a set of instructions from a CSV file and draws them appropriately. This works, but I need to manually save the produced page as a .vsdx file (i.e. without my macro code) after the fact.

What I'd like to do is specify the filename in the input file and have it produce a macro-free visio file of that name.

I've tried

Application.ActiveDocument.SaveAs filename

but this immediately generates a run-time error: "VB projects cannot be saved in macro-free files".

I understand that - I don't want my macro code in each of the (dozens of) flow charts I'm drawing. How can I suppress this error?

Thanks in advance.


Solution

  • If you want to have your macro(s) stored in a document file, then you'd want to have your macro generate a new document in which you draw your complex charts. But as @y4cine commented, you need to keep your code separate from your content, if you want to save your content as macro-free files.

    Otherwise you may be able to set Application.AlertResponse to whatever response Visio asks interactively when you try to save a file that has a macro as a macro-free format.