D
Dave
Hi,
I am working with Visio 2007 and tring to insert static text using VBA in a
shapes text area below the shape's data text. When I read the exising text
to add a newline of static text, the lines that contain fields with the
Shape Data are just garbage so I can't just read then in and add my static
text to the end and then set it back to the shapes text. I then used the
shapes Characters to read in existing text and then add my static text to
the end and set it back into the Shapes.Text but then I lose the fields in
the text area that shows the Shapes Data. Can someone point me in the
correct way to do this? Here is my current code that I use to try to insert
the static text at the end.
Private Sub InsertButton_Click()
Dim shp As Visio.Shape
Dim statements As String
Dim shpChars As Visio.Characters
Dim numChars, c, startRun, endRun
Dim tmpTxt As String
Set shp = Application.ActiveWindow.Selection(1)
' Get Shape formated text object.
Set shpChars = shp.Characters
' Get count of characters in formatted text.
numChars = shpChars.CharCount
' Init Local vars.
startRun = 0
endRun = 1
tmpTxt = ""
' Use formmated text object to extract text by lines.
For c = 0 To numChars
' Set begin marker to current position
' to search for next line.
shpChars.Begin = c
' Set end marker to begin marker plus one.
shpChars.End = c + 1
' Get start of next line
startRun = shpChars.RunBegin(visParaRun)
' Get end of next line
endRun = shpChars.RunEnd(visParaRun)
' Set begin and end markers to select
' the line we want.
shpChars.Begin = startRun
shpChars.End = endRun
tmpTxt = tmpTxt & shpChars.Text
' Set current position to end of this line.
c = endRun
Next c
tmpTxt = tmpTxt & vbNewLine & TemplateList.Text & vbNewLine
shp.Text = tmpTxt
Statement.Hide
End Sub
Thanks!
(e-mail address removed)
I am working with Visio 2007 and tring to insert static text using VBA in a
shapes text area below the shape's data text. When I read the exising text
to add a newline of static text, the lines that contain fields with the
Shape Data are just garbage so I can't just read then in and add my static
text to the end and then set it back to the shapes text. I then used the
shapes Characters to read in existing text and then add my static text to
the end and set it back into the Shapes.Text but then I lose the fields in
the text area that shows the Shapes Data. Can someone point me in the
correct way to do this? Here is my current code that I use to try to insert
the static text at the end.
Private Sub InsertButton_Click()
Dim shp As Visio.Shape
Dim statements As String
Dim shpChars As Visio.Characters
Dim numChars, c, startRun, endRun
Dim tmpTxt As String
Set shp = Application.ActiveWindow.Selection(1)
' Get Shape formated text object.
Set shpChars = shp.Characters
' Get count of characters in formatted text.
numChars = shpChars.CharCount
' Init Local vars.
startRun = 0
endRun = 1
tmpTxt = ""
' Use formmated text object to extract text by lines.
For c = 0 To numChars
' Set begin marker to current position
' to search for next line.
shpChars.Begin = c
' Set end marker to begin marker plus one.
shpChars.End = c + 1
' Get start of next line
startRun = shpChars.RunBegin(visParaRun)
' Get end of next line
endRun = shpChars.RunEnd(visParaRun)
' Set begin and end markers to select
' the line we want.
shpChars.Begin = startRun
shpChars.End = endRun
tmpTxt = tmpTxt & shpChars.Text
' Set current position to end of this line.
c = endRun
Next c
tmpTxt = tmpTxt & vbNewLine & TemplateList.Text & vbNewLine
shp.Text = tmpTxt
Statement.Hide
End Sub
Thanks!
(e-mail address removed)