Issue with mouse click in form

Started by Yacine, February 16, 2015, 10:31:12 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yacine

Hi guys,
I'm having an issue with a vba form.
The form has a list, in which I write all the distinct shape masters found on the page.
When a master is selected a subroutine shall select all the shapes belonging to this master.
The sub-routine starts with a activewindow.desellectall, then goes through all shapes and adds the right shape to the selection.
The issue is, that when I use the mouse to chose a master the deselection does not work.
Changing the value by keyboard does not show the problem.
Setting a break at the deselection line, also works without problem.
It looks like clicking in the form does change the activewindow.
But this does not make sense, because working with the keyboard would also not work.
Strange...

Option Explicit

Private Sub listMasters_AfterUpdate()
Dim shp As Shape

    ActiveWindow.DeselectAll

    For Each shp In ActivePage.Shapes
        If Not shp.Master Is Nothing Then
        If shp.Master = listMasters.value Then
            ActiveWindow.Select shp, visSelect
        End If
        End If
    Next shp
End Sub

Private Sub UserForm_Initialize()
    getMasters
End Sub

Private Sub getMasters()
    Dim Col As New Collection
    Dim shp As Shape
    Dim itm
   
    For Each shp In ActivePage.Shapes
        On Error Resume Next
        Col.Add shp.Master, shp.Master
        On Error GoTo 0
    Next shp
   
    listMasters.Clear
    For Each itm In Col
        listMasters.AddItem itm
    Next
End Sub
Yacine

Paul Herber

I think you might need something like:

Forms.Application.ProcessMessages

or the equivalent in VBA.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Yacine

Sounds like "doevents". I couldn't find a better one.
It did however not work.

But duplicating the deselection line, did help.
Ugly!

Thanks for the help.
Yacine