Hi,
I have a diagram which has annotation to shapes like
"[80010_1] Please listen carefully and confirm you made the following transaction. Please confirm the following Payment ".
I need to extract the annotation without the strike-through text and should enter that to a file.
The Resulting text should be "[80010_1] Please listen carefully and confirm the following Payment."
How to do this using VBA Macros?
Normally you could access a shape's text via the Text-property and be done with it. But in your case that won't work. I guess you have to use the characters object of the shape, and try to identify the strike-through parts of the text.
http://msdn.microsoft.com/en-us/library/aa342189%28v=office.12%29.aspx
And the corrosponding rows in the ShapeSheet:
http://msdn.microsoft.com/en-us/library/office/ff769034%28v=office.15%29.aspx
Thanks but I still dont get it. Can you pls tell me how to do this? Im breaking my head.
You can do it like this. Don't forget you may have to remove multiple spaces between the words.
Public Sub removeStrikeThrough( _
ByRef vsoshape As Visio.Shape)
Dim i As Integer
Dim strText As String
Dim endPos As Integer
Dim startPos As Integer
With vsoshape
startPos = 0
For i = 0 To .RowCount(visSectionCharacter) - 1
endPos = CharacterFormatEnd(vsoshape, startPos)
If .CellsSRC(visSectionCharacter, i, visCharacterStrikethru).ResultIU = 0 Then
strText = strText + Mid$(.Text, startPos + 1, endPos - startPos)
End If
startPos = endPos
Next
End With
Call MsgBox(strText)
End Sub
Private Function CharacterFormatEnd(visShape As Visio.Shape, ByVal iBegin As Integer) As Integer
Dim visChars As Visio.Characters
Dim iLen As Integer, i As Integer, iFirstRow As Integer, iRow As Integer
iRow = -1
iLen = Len(visShape.Text)
For i = iBegin To iLen
Set visChars = visShape.Characters
visChars.Begin = i
visChars.End = i + 1
If iRow = -1 Then iFirstRow = visChars.CharPropsRow(visBiasLeft)
iRow = visChars.CharPropsRow(visBiasLeft)
If iRow <> iFirstRow Then
'The row changed. We're done.
CharacterFormatEnd = i
Exit Function
End If
Next
CharacterFormatEnd = Len(visShape.Text)
End Function
Thanks Andy but it did not work for me.
My Annotation has the following text.
IF<GRETT_MSG>
[10000_n] <GREETING> message for...
PlayContact <CONTACT_FORMAL_1>
If ($numContacts > 1) {
[10010] ... or ...
PlayContact<CONTACT_FORMAL_2> }
If <GREET_TELEMARKETING_MESSAGE> == yes {
[10015] This is not a telemarketing call. }
[10020_n] ...<PLAY_MENU>, please press 1.
please press 1.
I want the strike-through text " [10020_n] ...<PLAY_MENU>, please press 1."
to be removed and the rest of the text should be printed as follows
IF<GRETT_MSG>
[10000_n] <GREETING> message for...
PlayContact <CONTACT_FORMAL_1>
If ($numContacts > 1) {
[10010] ... or ...
PlayContact<CONTACT_FORMAL_2> }
If <GREET_TELEMARKETING_MESSAGE> == yes {
[10015] This is not a telemarketing call. }
please press 1.
In your block of code
Set visChars = visShape.Characters the visChars is always "". the characters are not being fetched from annotation text.
How about a sample diagram.
Hi Andy,
I have attached the sample diagram.
I've added it as a double click on your annotation. The annotation is a grouped shape, so the text is on one of the sub-shapes, not the top level shape.
Excellent Andy and Thanks a Lot.
I made a single change in your code.
endPos = CharacterFormatEnd(vsoSubShape, startPos).
Im so happy.. Thanks again.
Just an idea, but I would have tried to use MS Word's capabilities to replace formated text in a string.
(Despite this solution would have been far less elegant than Andy's)
Hi Andy,
Thank you for your Code.
But Unfortunately it has some error. :(
I have attached file. I tried on that.
Can you help me to correct it