Measureing distance with freeform---please help

B

BCLivell

Hi everyone!

I need help with a way to meaure the total distance with freeform
tool. I can only get it to measure the distance between the two endpoints.
Essentially, I have route drawn to scale and I run the freeform tool around
and would like to get the distance for the entire route. Any ideas. Thank
you!!
 
C

Chris [Visio MVP]

It is possible with a little bit of VBA code:

- Select your freeform Shape
- Press Alt + F11 (to get the code editor)
- Make sure you can see the "Immediate Window" (View...)
- In the immediate window type this, then hit return:

?Visio.ActiveWindow.Selection(1).LengthIU

That will give you the length of the curve in inches. Multiply by 25.4 to
get millimeters.
 
B

BCLivell

Chris-
I did as you explained. When I hit enter, I get a value of "0".
Any ideas? Thank you!
 
C

Chris [Visio MVP]

There's a bug in Visio - if the line is open, ie: Not Filled, then it
returns 0.

Do this:

- Select your shape
- Paste the code block below into the VBA editor
- Put the cursor somewhere in the code procedure
- Press F5 to run it.

--------------------------------------------

Sub MeasureIt()

Dim shp As Visio.Shape
Dim f As String
Dim L1 As Double, L2 As Double

Set shp = Visio.ActiveWindow.Selection(1)

'// Set NoFill to false to work around the bug:

f = shp.CellsU("Geometry1.NoFill").FormulaU
shp.CellsU("Geometry1.NoFill").FormulaU = "0"

L1 = shp.LengthIU
L2 = Sqr( _
(shp.CellsU("EndX").ResultIU -
shp.CellsU("BeginX").ResultIU) ^ 2 + _
(shp.CellsU("EndY").ResultIU -
shp.CellsU("BeginY").ResultIU) ^ 2 _
)


Debug.Print "Shape length is: " & L1 - L2 & " inches."
MsgBox "Shape length is: " & L1 - L2 & " inches."

'// Restore the formula:
shp.CellsU("Geometry1.NoFill").FormulaU = f

End Sub
 
B

BCLivell

Chris - Thank you so much for taking the time to help me with this. I copied
the code, but when I go to run it, I get a "compie error: syntax error"
message. It highlights this part:

L2 = Sqr( _
(shp.CellsU("EndX").ResultIU -

Thank you!
Brian
 

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