ActiveXcmd bugs sub: ThisDoc.Saved = True & ThisDoc.Close | solved! but REASON?

Started by RSut, March 30, 2014, 07:49:00 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

RSut

****** Story of a bug, with a work-around, but without any explanation.
****** Can you explain, or is is just that activeX buttons should be avoided?

During a pilot expt in  VBA  to test automated closure of a visio doc (with and without ThisDocument.Save /ThisDocument.Saved=1 ), I set up an *activeX command button* on the visio drawing page to test occurrence of 'save'.

I was surprised to find that clicking the *activeX command button*, just once, stopped Sub CloseNoSave() from functioning (the doc did not close). This occurred even when the sub for the activeX button_click event contained NO content code (eg, no call to drive another procedure), and even if the button had NO code at all (as for activeX Button on page-3 of attached file).

Here is the code that was stopped by clicking activeX button BEFORE running this sub:
Sub CloseNoSave()
    Application.AlertResponse = 1
    ThisDocument.Saved = True
    ThisDocument.Close
    'Application.Quit
End Sub

The activeX button did not stop the function of Sub CloseWithSave():
Sub CloseWithSave()
    Application.AlertResponse = 1
    ThisDocument.Save
    ThisDocument.Close
    'Application.Quit
End Sub

UserForm cmd buttons had NO such effect. But clicking a visio shape (not even selecting it) was sufficient to cause this stoppage, PROVIDED that an activeX button was located somewhere on the same page!.

A SOLUTION: This block was reproducibly overcome with an automatic change of page to a new and irrelevant page (here: "Page-2"). As the code line that followed still closed the document without change, this page change is not saved:

Here is the modified code:
Sub CloseNoSave()
    Application.ActiveWindow.Page = Application.ActiveDocument.Pages.ItemU("Page-2")
    Application.AlertResponse = 1
    ThisDocument.Saved = True
    ThisDocument.Close
    'Application.Quit
End Sub

This issue does not occur Excel.
Can anyone explain what is going on here?
File attached!

Thanks,
RSut