How can I get the character length data from the character section?

Started by whowho, May 09, 2018, 08:45:41 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

whowho

The image is here : https://drive.google.com/file/d/1gfBwIrBvF3q9di2RpBNdHpW4AsSfAlbk/view?usp=sharing

I'm making an autohotkey macro using VBA.
Can I get the length of the character in a row by VBA?
I have to get text that its strikethru value is false. (Not remove the text in visio file. Get text to other format.)
I tried the RunBegin, RunEnd methods, but it didn't work...

wapperdude

In the case of strike-thru, simple method exists.  Merely change the strike-thru cell in the shapesheet.  See code below.  This code actually inverts the strike-thru setting, but could be easily modified to merely set the strike-thru to false (value = 0).  This approach could be extended to other cells in the character section, e.g., font.  The style setting is more complex as it can be an accumulation of settings...bold = 17, italic = 34, bold & italic = 51, etc.

HTH.
Wapperdude


Sub InvStkThru()
    Dim vsoShp As Shape
    Dim maxRow As Integer
    Dim i As Integer
   
    Set vsoShp = ActiveWindow.Selection(1)
    maxRow = vsoShp.RowCount(visSectionCharacter) - 1
    For i = 0 To maxRow
        If vsoShp.CellsSRC(visSectionCharacter, i, visCharacterStrikethru).Result(none) = 1 Then
            vsoShp.CellsSRC(visSectionCharacter, i, visCharacterStrikethru).FormulaU = 0
        Else
            vsoShp.CellsSRC(visSectionCharacter, i, visCharacterStrikethru).FormulaU = 1
        End If
    Next
End Sub

Visio 2019 Pro

bhughes89

RunBegin and RunEnd actually search outside of the Begin and End properties of a Characters object. The Begin / End properties basically represent an imaginary selection of text, so when a new Characters object is initialized it's Begin / End properties are set to the start and end of the shape's text. So, using RunBegin / RunEnd right after creating a new Characters object returns RunBegin = Begin and RunEnd = End.

To use RunEnd to find actual runs of similarly-formatted text, we simply need to change our imaginary selection to just the very start of all the text: End = Begin + 1

NOTE: Changing the Begin / End properties of a Characters object does NOT change the text. It only changes what text we are looking at.


Each character run represents a row in the Characters section of the ShapeSheet, so we can put together a pretty simple loop to find character runs, find out if they have strikethru or not, and print out our results.

Public Sub GetStrikeThruLg()
    Dim vsoShp As Shape
    Dim vsoChars As Characters
    Dim iRow As Integer
   
    'if no shape has been selected, throw an error and exit
    If ActiveWindow.Selection.Count = 0 Then
        MsgBox "Please select a shape before running this procedure."
        Exit Sub
    End If
   
    Set vsoShp = ActiveWindow.Selection(1)
    Set vsoChars = vsoShp.Characters
   
    'set Chars obj End property to first char
    'this basically sets the starting point for the RunEnd search
    vsoChars.End = vsoChars.Begin + 1
   
    'search thru shape's chars to find runs of similarly-formatted chars
    'until we reach end of shape's chars
    Do
        'find next char run and get its corresponding row in chars section
        vsoChars.End = vsoChars.RunEnd(visCharPropRow)
        iRow = vsoChars.CharPropsRow(visBiasLetVisioChoose)
       
        'print out how many chars
        If vsoShp.CellsSRC(visSectionCharacter, iRow, visCharacterStrikethru).ResultIU = 0 Then
            Debug.Print "char row " & iRow & ": found " & vsoChars.CharCount & " chars without strikethru"
        Else
            Debug.Print "char row " & iRow & ": found 0 chars with strikethru"
        End If
       
        'reset Chars obj Begin and End properties for next search
        vsoChars.Begin = vsoChars.End
        vsoChars.End = vsoChars.Begin + 1
    Loop Until vsoChars.End >= vsoShp.CharCount
End Sub