2

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.

David Fulton
  • 737
  • 7
  • 16
  • 1
    You don't need to store your macros in the drawing files. Save them instead in a stencil, make a template with that stencil loaded and start new drawings from there. – y4cine Jan 24 '19 at 17:39

1 Answers1

2

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.

Jon Fournier
  • 4,299
  • 3
  • 33
  • 43
  • Right - so the solution is to either (a) create a stencil and put the macro there or (b) have the macro generate a whole new document as part of the process? (I'll also try the "cheap and cheerful" approach of automatically hiding the prompt, but I'm less optimistic of this, as I don't get the prompt from the macro - just a run-time error). – David Fulton Jan 26 '19 at 09:33
  • Yeah that pretty much sums it up. – Jon Fournier Jan 26 '19 at 19:10