S
Stumple
I am trying to set the yellow text handle and it's location. I found some
code from an MS employee that sets it for connectors. I am using this code
and most of the time it works properly but sometimes when my connectors are a
bit longer the text handle and associated text is way off from the location
of the line.
What it looks like is the text handle is away from the line and then the
text is a ways away from the handle. Does anyone know how to re-center the
text handle back to the connector and then center the text back to the text
handle?
Thank you.
The code I found is below.
Public Sub AddTextControlHandle()
Dim vsoMaster As Visio.Master
Dim vsoMasterCopy As Visio.Master
Dim vsoShape As Visio.Shape
Dim vsoPage As Visio.Page
Dim masterCount As Integer
Dim shapeCount As Integer
masterCount = 0
shapeCount = 0
'Iterate through masters in current document searching for Dynamic
Connectors
For Each vsoMaster In ActiveDocument.Masters
If UCase(Left(vsoMaster.NameU, 17)) = "DYNAMIC CONNECTOR" Then
Set vsoMasterCopy = vsoMaster.Open
Set vsoShape = vsoMasterCopy.Shapes(1)
'Check to see if connector already has text control handle
If vsoShape.CellExistsU("Controls.TextPosition", 0) = 0 Then
'Add text control handle
vsoShape.AddNamedRow visSectionControls, "TextPosition", 0
vsoShape.CellsU("Controls.TextPosition.X").FormulaU = "Width
* 0.5"
vsoShape.CellsU("Controls.TextPosition.Y").FormulaU =
"Height*0.5"
vsoShape.CellsU("Controls.TextPosition.XDyn").FormulaU =
"Controls.TextPosition.X"
vsoShape.CellsU("Controls.TextPosition.YDyn").FormulaU =
"Controls.TextPosition.Y"
vsoShape.CellsU("Controls.TextPosition.XCon").FormulaU =
"IF(OR(STRSAME(SHAPETEXT(TheText)," + Chr(34) + Chr(34) + "),HideText),5,0)"
vsoShape.CellsU("Controls.TextPosition.CanGlue").FormulaU = 0
vsoShape.CellsU("Controls.TextPosition.Prompt").FormulaU =
Chr(34) + "Reposition Text" + Chr(34)
'Add text transform
vsoShape.CellsU("TxtPinX").FormulaU =
"SETATREF(Controls.TextPosition)"
vsoShape.CellsU("TxtPinY").FormulaU =
"SETATREF(Controls.TextPosition.Y)"
masterCount = masterCount + 1
End If
vsoMasterCopy.Close
End If
Next
'Iterate through shapes in document searching for instances of masters
in fixed list
For Each vsoPage In ActiveDocument.Pages
For Each vsoShape In vsoPage.Shapes
'Check for dynamic connector
If UCase(Left(vsoShape.Master.NameU, 17)) = "DYNAMIC CONNECTOR"
Then
'Get current text block position
Dim x As Double, y As Double
x = vsoShape.CellsU("TxtPinX").ResultIU
y = vsoShape.CellsU("TxtPinY").ResultIU
'Reset text transform
vsoShape.CellsU("TxtPinX").FormulaU = "="
vsoShape.CellsU("TxtPinY").FormulaU = "="
'Update text position
vsoShape.CellsU("TxtPinX").ResultIU = x
vsoShape.CellsU("TxtPinY").ResultIU = y
shapeCount = shapeCount + 1
End If
Next
Next
MsgBox "Fixed " + CStr(masterCount) + " Dynamic Connector masters and "
+ CStr(shapeCount) + " shapes."
End Sub
code from an MS employee that sets it for connectors. I am using this code
and most of the time it works properly but sometimes when my connectors are a
bit longer the text handle and associated text is way off from the location
of the line.
What it looks like is the text handle is away from the line and then the
text is a ways away from the handle. Does anyone know how to re-center the
text handle back to the connector and then center the text back to the text
handle?
Thank you.
The code I found is below.
Public Sub AddTextControlHandle()
Dim vsoMaster As Visio.Master
Dim vsoMasterCopy As Visio.Master
Dim vsoShape As Visio.Shape
Dim vsoPage As Visio.Page
Dim masterCount As Integer
Dim shapeCount As Integer
masterCount = 0
shapeCount = 0
'Iterate through masters in current document searching for Dynamic
Connectors
For Each vsoMaster In ActiveDocument.Masters
If UCase(Left(vsoMaster.NameU, 17)) = "DYNAMIC CONNECTOR" Then
Set vsoMasterCopy = vsoMaster.Open
Set vsoShape = vsoMasterCopy.Shapes(1)
'Check to see if connector already has text control handle
If vsoShape.CellExistsU("Controls.TextPosition", 0) = 0 Then
'Add text control handle
vsoShape.AddNamedRow visSectionControls, "TextPosition", 0
vsoShape.CellsU("Controls.TextPosition.X").FormulaU = "Width
* 0.5"
vsoShape.CellsU("Controls.TextPosition.Y").FormulaU =
"Height*0.5"
vsoShape.CellsU("Controls.TextPosition.XDyn").FormulaU =
"Controls.TextPosition.X"
vsoShape.CellsU("Controls.TextPosition.YDyn").FormulaU =
"Controls.TextPosition.Y"
vsoShape.CellsU("Controls.TextPosition.XCon").FormulaU =
"IF(OR(STRSAME(SHAPETEXT(TheText)," + Chr(34) + Chr(34) + "),HideText),5,0)"
vsoShape.CellsU("Controls.TextPosition.CanGlue").FormulaU = 0
vsoShape.CellsU("Controls.TextPosition.Prompt").FormulaU =
Chr(34) + "Reposition Text" + Chr(34)
'Add text transform
vsoShape.CellsU("TxtPinX").FormulaU =
"SETATREF(Controls.TextPosition)"
vsoShape.CellsU("TxtPinY").FormulaU =
"SETATREF(Controls.TextPosition.Y)"
masterCount = masterCount + 1
End If
vsoMasterCopy.Close
End If
Next
'Iterate through shapes in document searching for instances of masters
in fixed list
For Each vsoPage In ActiveDocument.Pages
For Each vsoShape In vsoPage.Shapes
'Check for dynamic connector
If UCase(Left(vsoShape.Master.NameU, 17)) = "DYNAMIC CONNECTOR"
Then
'Get current text block position
Dim x As Double, y As Double
x = vsoShape.CellsU("TxtPinX").ResultIU
y = vsoShape.CellsU("TxtPinY").ResultIU
'Reset text transform
vsoShape.CellsU("TxtPinX").FormulaU = "="
vsoShape.CellsU("TxtPinY").FormulaU = "="
'Update text position
vsoShape.CellsU("TxtPinX").ResultIU = x
vsoShape.CellsU("TxtPinY").ResultIU = y
shapeCount = shapeCount + 1
End If
Next
Next
MsgBox "Fixed " + CStr(masterCount) + " Dynamic Connector masters and "
+ CStr(shapeCount) + " shapes."
End Sub