Visio Guy

Visio Discussions => Programming & Code => Topic started by: Lars-Erik on July 15, 2008, 01:07:38 PM

Title: Application.ActiveDocument.Close
Post by: Lars-Erik on July 15, 2008, 01:07:38 PM
When i try to run this, it works fine. When however i try to run this from a menu I added using VBA... I get an error saying:

"Requested operation is presently disabled"

Any thoughts? I see no reason this should just work...

- Lars
Title: Re: Application.ActiveDocument.Close
Post by: Visio Guy on July 15, 2008, 02:40:57 PM
I think that the menu item doesn't have the same context as VBA. So it doesn't know what "Application" is. A VBA procedure does, and so does the Immediate/Debug window, where you can type this in directly and get it to run.

You'd need to call a procedure that can make this line work, or try some scary in-line call like: GetObject("visio.application").ActiveDocument.Close, then pray and throw salt over your shoulder.
Title: Re: Application.ActiveDocument.Close
Post by: Lars-Erik on July 15, 2008, 02:55:26 PM
The menu is calling a macro in a module, not trying to close the activedocument straight from the menu.
So the menu runs, for example sub test(), and fails to close the document.
When i use the run macro (alt + f8) and then run test() it DOES work, thats where I got confused... I'll give the GetObject("visio.application").ActiveDocument.Close a try.

- Lars
Title: Re: Application.ActiveDocument.Close
Post by: Visio Guy on July 15, 2008, 04:15:14 PM
Hmm,

Is the macro in the module getting reached (ie: Debug.Print "Got here!")

I wouldn't recommend the whole GetObject thing, it was just an icky work-around...it might work, but I wouldn't put it in a book :)
Title: Re: Application.ActiveDocument.Close
Post by: aledlund on July 19, 2008, 01:26:27 PM
one technique is to put a variable/ property into the form and when you call to open the form, initialize the property first


.. form code
dim m_visapp as visio.application

public property get pVisApp as visio.application
   if m_visapp is nothing then
       set m_visapp = thisdocument.application
   else
       set pVisApp = m_visapp
  end if
end property
public property set pVisApp(value as visio.application)
   ' do some testing like above first
   set m_visapp = value
end if
...


so when you call it


    set frmMyForm.pVisapp = thisdocument.application
    frmMyForm.show


that way you can pass parameters (and validate them) back and forth

al