Find the shape with the focus, using VBA

S

stijn

Hello Friends,

I succeed to find any propertie of each shape, in my document, using VBA.

One problem : I can't find the shape which has been 'focussed' (last selected,
with the green squares around it)

Can you pls help me out?

Thanks,
Stijn
 
J

John Marshall, MVP

Try something like

Dim VsoSelect As Visio.Selection
Dim VsoShape as Visio.Shape

Set VsoSelect = Visio.ActiveWindow.Selection

If VsoSelect.Count > 0 Then
for each VsoShape in VsoSelect

next VsoShape
else
MsgBox "You Must Have Something Selected"
end if


John... Visio MVP

Need stencils or ideas? http://www.mvps.org/visio/3rdparty.htm
Need VBA examples? http://www.mvps.org/visio/VBA.htm
Common Visio Questions http://www.mvps.org/visio/common_questions.htm
Visio Wishlist http://www.mvps.org/visio/wish_list.htm
 
S

stijn

Hi John,

Thx very much, works perfect ..

Now I'm trying to reach the Custom properties of my shape.
In VB it's CustomPropertie(f , n) but I can't find a similar thing
in VBA :

RS.Open "select * from NITTO.INVHW WHERE HWNUM='" & test & "'", CONAS400

Set MyShape = ActiveShape '=your solution in a seperate function ;-)

Myshape.????? = RS.Fields(1)
 
S

stijn

Hi John,

I found how to read the properties ... (in the VBA examples)

Set MyCell = MyShape.CellsSRC(Visio.visSectionProp, f, 0)
'MsgBox MyCell.ResultStr(Visio.visNonPrinting)


MsgBox f & " : " & MyCell.ResultStr("")

But not how to write a value in it...

Can you help me out again, pls?

greetz

Stijn
 
S

stijn

Hi John,

Works perfect.
It took some time before I understood how to fill in a string value ...;-)

Now, I would be able to retrieve the location (x,y) of a shape in a drawing.
I feel, I'm missing some basic knowledge of how visio handles, shapes,
cells, formula's, ... but I'm learning every day.

I tried to figure out things like "DistanceFromPoint" and other stuff,
but I don't really understand it. Therefore ... Could you please help
me out again to get these coords of a shape.

Txh again,

Stijn
 
J

John Marshall, MVP

The DistanceFromPoint tells you how far away a point is from a shape. The
trick is that the the distance is not from the pin x,y, but from the nearest
part on the shape.

There is some sample code for "Distance From" at
http://www.mvps.org/visio/VBA.htm

John... Visio MVP

Need stencils or ideas? http://www.mvps.org/visio/3rdparty.htm
Need VBA examples? http://www.mvps.org/visio/VBA.htm
Common Visio Questions http://www.mvps.org/visio/common_questions.htm
Visio Wishlist http://www.mvps.org/visio/wish_list.htm
 
S

stijn

Hi John,

That's exactly what I tried...
But I need the x and y, not the distance from another shape.
I would like to check on which exact position of a drawing, I put
a shape.
Maybe I can get this x and y, using DistanceFromPoint, but I
really don't understand how.

grts

Stijn
 
M

Mark Nelson [MS]

A shape's location is defined by its PinX and PinY cells. That returns the
shape position relative to its container. That container may be the page or
another shape if it's in a group. You can use the Shape.XYToPage method to
have Visio give you page coordinates no matter how nested your shape is, but
for this you must pass in LocPinX and LocPinY cell values (since the
function converts local coordinates not container coordinates).

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

John Marshall, MVP

and here is some code to see how the XYtoPage and XPFromPage work:
Public Sub XYTest()

Dim shpObj As Visio.Shape
Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double

x1 = 0
y1 = 0

For Each shpObj In ActivePage.Shapes
shpObj.XYToPage x1, y1, x2, y2
Debug.Print x1, y1, x2, y2, " ";

shpObj.XYFromPage x1, y1, x2, y2
Debug.Print x2, y2
Next shpObj

End Sub

--
John... Visio MVP

Need stencils or ideas? http://www.mvps.org/visio/3rdparty.htm
Need VBA examples? http://www.mvps.org/visio/VBA.htm
Common Visio Questions http://www.mvps.org/visio/common_questions.htm
Visio Wishlist http://www.mvps.org/visio/wish_list.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top