Why this Visio exception

Started by cnayan, August 26, 2013, 08:51:40 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

cnayan

This is weird. Why does Visio throw exception?

Scenario:
==========
1. Open new instance of Visio.
2. Press CTRL+N for a blank new document.
3. Goto VB editor.
4. Open the default "ThisDocument" code file.
5. Paste the following code.
Sub test()
    Application.ActiveWindow.SelectAll
End Sub

6. Execute the subroutine "test".

You will observe this exception for code line "Application.ActiveWindow.SelectAll":

---------------------------
Microsoft Visual Basic for Applications
---------------------------
Run-time error '-2032465766 (86db089a)':



Requested operation is presently disabled.
---------------------------
OK   Help   
---------------------------


Does anyone know why?

Surrogate

may be because new page haven't shapes.
Please add some shape and execute the subroutine "test" again :)

cnayan

@Surrogate:

Well, it does work after adding at least 1 object on page. :) But, doesn't it feel weird?
I mean, what is the sense in throwing exception if there is nothing to select?
This introduces unneccessary programability complications (try/catch).

I am guessing, this is Visio's unneccessary feature :D, otherwise please suggest the known reasons.

vojo

probably done this way because, after select/selectall, many operations can be done against the selection and probably some of them have
"bad things" happen if nothing there.    Ie its a case of try/catch here....or....try/catch in various other functions using select/selectall

Just my guess