How can I do a test to know when a shape is selected or no in VBA?

Started by Miguel, April 04, 2017, 06:44:37 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Miguel

Hello people!

How can I do a test to know when a shape is selected or no in VBA?

Thank you !

Surrogate

Hola amigo!

How will you define the Shape: by ID, by Name ?
Sub test()
Dim tst As Boolean
Dim id_ As Integer
Dim name_ As String
id_ = InputBox("Enter shape ID")
tst = CheckByID(id_)
MsgBox "Shape with ID " & id_ & " is selected ? " & tst
name_ = InputBox("Enter shape Name")
tst = CheckByName(name_)
MsgBox "Shape with Name " & name_ & " is selected ? " & tst
End Sub
Function CheckByID(idn As Integer) As Boolean
Dim sh As Shape, shp As Shape
CheckByID = False
Set sh = ActivePage.Shapes(1)
Dim sl As Selection
Set sl = ActiveWindow.Selection
If sl.Count = 0 Then MsgBox "No shapes selected !": Exit Function
For Each shp In ActiveWindow.Selection
If shp.ID = idn Then CheckByID = True: Exit Function
Next
End Function
Function CheckByName(shn As String) As Boolean
CheckByName = False
Dim sh As Shape, shp As Shape
Set sh = ActivePage.Shapes(1)
Dim sl As Selection
Set sl = ActiveWindow.Selection
If sl.Count = 0 Then MsgBox "No shapes selected !": Exit Function
For Each shp In ActiveWindow.Selection
If shp.Name = shn Then CheckByName = True: Exit Function
Next
End Function


Miguel

Tkx amigo!

My shape are defined by the name!  ;D

But I have this code :

  If vsoSelection.Count <> 1 Then  'Une Shape doit etre sélectionné
        MsgBox "Select a shape, then re-run macro."
        Exit Sub
    Else
        Set vsoShape = ActiveWindow.Selection(1)
    End If
End Sub



Surrogate

You code just set shape variable for single selected shape ! Without test :)

Miguel

Yes, it's a good job!
You are of great help to me!  ::)

And do you know if there is a method which could know when Z shapes are glued or not ?


Miguel

Typping error. Sorry.

I'm talking about a method or little code which check if a 2 shapes are glued together.


Surrogate

Quote from: Miguel on April 04, 2017, 11:44:57 AMwhich check if a 2 shapes are glued together
how you want specify these shapes: by IDs, by Names or just select shapes at page ? Does it matter who to whom is glued?

Miguel

Hum I will be more precise.

I have 2 shapes : a rectangle and a triangle. There are very simple. The Rectangle has 16 point of controls and the triangle 2. All of the points of controls are Inward&Outward!.
So when one of a point of controls of my triangle touch one of the point of controls of the rectangle, my 2 shape glue together. So the bonding is done manually.

Now, I would like to write a little code which check if the bonding exist. For example, if the bonding exist so i colour my triangle in red.

If   MY SHAPES ARE GLUED   then
             xxxxxxxxxx
              xxxxxxxxxx



I hope that you understand now my problem :) ::)
Thank you

Surrogate


Miguel

Quote from: Surrogate on April 05, 2017, 01:00:50 PM
But how you specify that rectangle and triangle ?
This 2 shapes there are in my stencil. The shapes contain data imported from an excel table. 

Surrogate

Quote from: Miguel on April 05, 2017, 01:05:00 PMThis 2 shapes there are in my stencil
Your stencil is certain document ! And masters Rectangle and Triangle are different.
We can check connections ONLY on page !
Quote from: Miguel on April 05, 2017, 01:05:00 PMThe shapes contain data imported from an excel table.
NEVERMIND !

Miguel

Yes of course, the masters are different!

Quote from: Surrogate on April 05, 2017, 01:11:35 PM
We can check connections ONLY on page !

Can you give me an example please ?

Surrogate