Application.ActiveDocument.Close

Started by Lars-Erik, July 15, 2008, 01:07:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Lars-Erik

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

Visio Guy

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.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Lars-Erik

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

Visio Guy

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 :)
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

aledlund

#4
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