Author Topic: How to remove the Strikethrough text in Visio Annotation using VBA  (Read 4478 times)

0 Members and 1 Guest are viewing this topic.

enramya82

  • Newbie
  • *
  • Posts: 6
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?
« Last Edit: August 04, 2014, 03:56:10 AM by enramya82 »

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: How to remove the Strikethrough text in Visio Annotation using VBA
« Reply #1 on: August 04, 2014, 04: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

enramya82

  • Newbie
  • *
  • Posts: 6
Re: How to remove the Strikethrough text in Visio Annotation using VBA
« Reply #2 on: August 04, 2014, 05:00:59 AM »
Thanks but I still dont get it. Can you pls tell me how to do this? Im breaking my head.

AndyW

  • Sr. Member
  • ****
  • Posts: 320
    • PC Mimic Diagram
Re: How to remove the Strikethrough text in Visio Annotation using VBA
« Reply #3 on: August 04, 2014, 06:25:00 AM »
You can do it like this. Don't forget you may have to remove multiple spaces between the words.

Code
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
Live life with an open mind

enramya82

  • Newbie
  • *
  • Posts: 6
Re: How to remove the Strikethrough text in Visio Annotation using VBA
« Reply #4 on: August 04, 2014, 06: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.
« Last Edit: August 04, 2014, 07:11:17 AM by enramya82 »

AndyW

  • Sr. Member
  • ****
  • Posts: 320
    • PC Mimic Diagram
Re: How to remove the Strikethrough text in Visio Annotation using VBA
« Reply #5 on: August 04, 2014, 07:07:07 AM »
How about a sample diagram.
Live life with an open mind

enramya82

  • Newbie
  • *
  • Posts: 6
Re: How to remove the Strikethrough text in Visio Annotation using VBA
« Reply #6 on: August 04, 2014, 07:15:09 AM »
Hi Andy,

I have attached the sample diagram.

AndyW

  • Sr. Member
  • ****
  • Posts: 320
    • PC Mimic Diagram
Re: How to remove the Strikethrough text in Visio Annotation using VBA
« Reply #7 on: August 04, 2014, 07:39:14 AM »
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.
Live life with an open mind

enramya82

  • Newbie
  • *
  • Posts: 6
Re: How to remove the Strikethrough text in Visio Annotation using VBA
« Reply #8 on: August 04, 2014, 09:49:44 AM »
Excellent Andy and Thanks a Lot.
I made a single change in your code.

endPos = CharacterFormatEnd(vsoSubShape, startPos).
Im so happy.. Thanks again.

Yacine

  • Hero Member
  • *****
  • Posts: 2703
Re: How to remove the Strikethrough text in Visio Annotation using VBA
« Reply #9 on: August 04, 2014, 01: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)
Yacine

vishalayadav94

  • Newbie
  • *
  • Posts: 1
Re: How to remove the Strikethrough text in Visio Annotation using VBA
« Reply #10 on: May 09, 2020, 11:16:39 AM »
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