Dynamically compile/syntax check another document

Started by AndyW, July 28, 2009, 10:13:20 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AndyW

My Visio application opens another visio document that contains code, this then calls methods in this document using callbyname. This all works fine. However, if  the visio document being opened has some compilation errors this then causes my application to stop. Ideally I would like to catch this error at runtime, give a message and then not use the document. Alternatively, is it possible to compile this other document to determine if it contains any errors or syntax check it.

I know ideally there should not be compile time errors, but if for some reason the application has changed but the additional document has not been updated I would like to be able to handle this gracefully.

This is all VBA.
Live life with an open mind

Visio Guy

Good question, Andy! I really don't know - VBA can be rather weird sometimes.

Have you tried wrapping the open-other-document code in some sort of error-catching block? I'm not sure if this would trap the compilation error, but it is worth a shot:


Sub OpenOtherVbaVisioDoc

  On Error Goto Error_OpenOtherVbaVisioDoc

  ' Open document
  ' Do stuff...

  Exit Sub

Error_OpenOtherVbaVisioDoc:

  Debug.Print "Oh no, a compilation error!"

End Sub
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

AndyW

I tried adding error handling, but it seems I am unable to catch a compilation error.
Live life with an open mind

Visio Guy

Yeah, I wasn't sure it would work.

There is an OpenEx flag that allows you to open a document with macros disabled, which might help with the compilation error, but then, well, your macros won't be callable.  ???
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

AndyW

#4
Using OpenEx with macros disabled on another document is worse than that as it stops the code in the current document as well!
Live life with an open mind

Visio Guy

For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010