Shape Text Fields

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)
 
D

Dave

Thanks for the reply.

This doesn't work because the first couple lines of in the Shape's text area
are Fields that show Shape Data. The shape data can be changed on the fly
by right clicking the shape and edit the data but when I add the static text
to the end, it removes the fields from the first couple lines. I need a way
to add text in the shape's text area without loosing the fields showing
shape data in the existing shape's text.

Thanks!
 
J

JuneTheSecond

Dave,

Maybe, you need to modify by the formula
in the text field cell, not by the text string.
For example,
shp.Cells("Fields.Value").Formula = _
shp.Cells("Fields.Value").Formula & "&Char(13)&Char(10)&" _
& DQ(TextBox1.text)
where, DQ is
Function DQ(text As String) As String
DQ = Chr(34) & text & Chr(34)
End Function
 
D

Dave

Hi,

Thanks for the reply! I do not want to modify the text in the Field, I want
to add static text on a new line below the text with fields using VBA.

Thanks!
 
D

Dave

Hi,

Got the answer from Visio Guy's forums. Posting her incase anyone else
wanted to know. My original code was trying to read in the existing text,
special field text as well and then reset all the text to include the new
string. Instead, just set characters start run to the end of existing text
and then add it.

Hope Visio Guy doesn't mind me posting his solution here to the public.

Sub InsertDumbTextWithoutDestroyingSmartText()

Dim shp As Visio.Shape
Set shp = Visio.ActiveWindow.Selection(1)

Dim chrs As Visio.Characters
Set chrs = shp.Characters

chrs.Begin = shp.Characters.End
chrs.End = shp.Characters.End
chrs.Text = vbCrLf & "Bob"

End Sub
 

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