Visio Guy

Visio Discussions => General Visio => Topic started by: enramya82 on August 04, 2014, 08:31:59 AM

Title: How to remove the Strikethrough text in Visio Annotation using VBA
Post by: enramya82 on August 04, 2014, 08:31:59 AM
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?
Title: Re: How to remove the Strikethrough text in Visio Annotation using VBA
Post by: Jumpy on August 04, 2014, 09:33:26 AM
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
Title: Re: How to remove the Strikethrough text in Visio Annotation using VBA
Post by: enramya82 on August 04, 2014, 10:00:59 AM
Thanks but I still dont get it. Can you pls tell me how to do this? Im breaking my head.
Title: Re: How to remove the Strikethrough text in Visio Annotation using VBA
Post by: AndyW on August 04, 2014, 11:25:00 AM
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
Title: Re: How to remove the Strikethrough text in Visio Annotation using VBA
Post by: enramya82 on August 04, 2014, 11:55:17 AM
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.
Title: Re: How to remove the Strikethrough text in Visio Annotation using VBA
Post by: AndyW on August 04, 2014, 12:07:07 PM
How about a sample diagram.
Title: Re: How to remove the Strikethrough text in Visio Annotation using VBA
Post by: enramya82 on August 04, 2014, 12:15:09 PM
Hi Andy,

I have attached the sample diagram.
Title: Re: How to remove the Strikethrough text in Visio Annotation using VBA
Post by: AndyW on August 04, 2014, 12:39:14 PM
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.
Title: Re: How to remove the Strikethrough text in Visio Annotation using VBA
Post by: enramya82 on August 04, 2014, 02:49:44 PM
Excellent Andy and Thanks a Lot.
I made a single change in your code.

endPos = CharacterFormatEnd(vsoSubShape, startPos).
Im so happy.. Thanks again.
Title: Re: How to remove the Strikethrough text in Visio Annotation using VBA
Post by: Yacine on August 04, 2014, 06:25:45 PM
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)
Title: Re: How to remove the Strikethrough text in Visio Annotation using VBA
Post by: vishalayadav94 on May 09, 2020, 04:16:39 PM
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