Link to home
Start Free TrialLog in
Avatar of Lupo09
Lupo09Flag for Germany

asked on

Visio: Problem inserting linfeed in Shape.Text using vba

Hi Visio-Folks,
I'm facing a strange behaviour when inserting linefeeds in shape texts in an orgchart diagramm.

When inserting standard text without linefeeds, everything runs smoothly.

But I want to insert a number of lines and as soon as I add chr(10) or vbCrLf it begins to get slow. The more linefeeds I have, the slower it gets...

I have made the following test to proof it (in order to show the effect, I build up texts with 20 lines):

(Prior to running the test I created a orgchart with a number of shapes)

Sub testTextInsert(testType As Integer)
    'testType = 1 -> Test with vbCrLf
    'testType = 2 -> Test without vbCrLf
    Dim myTimer, timerTotal
    myTimer = Timer
    Dim vShp As Visio.Shape
    Dim strText As String
    Dim i, j
    For Each vShp In ActiveDocument.Pages(1).Shapes
        If vShp.OneD = False Then  don't put text to connectors...
            j = j + 1
            myTimer = Timer
            strText = ""
            For i = 1 To 20
                If testType = 1 Then strText = strText & vbCrLf & "Here goes some text I want to add ... Line " & i
                If testType = 2 Then strText = strText & " " & "Here goes some text I want to add ... Line " & i    'space instead of linefeed
            Next
            vShp.Text = strText
            Debug.Print Timer - myTimer
            timerTotal = timerTotal + (Timer - myTimer)
            DoEvents
        End If
    Next
   
    Debug.Print j; " Shapes, Average time: " & timerTotal / j & " sec"
End Sub


I tested with an orgchart with 13 shapes (position shapes).
Result:
    - with linefeed (vbcrlf): average time: 4.30 seconds
    - without linefeed: average time: 0.34 seconds

As I have some quite complex orgcharts, the procedure takes some minutes and my customer is impatient...


Does anybody have an idea what's going on here or what I have misunderstood?

Thanks a lot!

Kai
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lupo09

ASKER

Very interesting, wasn't aware of that setting.
That reduces the average time per shape from 4.3 to 1,3 seconds (which still is 3-4 times longer than without linefeeds - in my case).

Multiplied by a whole bunch of pages full of shapes I will save a lot of time!

Thank you so far!

Anyway, I would like to understand why Visio finds it so hard to insert linefeeds...
Maybe some further ideas show up?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lupo09

ASKER

Thanks a lot for your answers, it helped understand some more details.

I'll set scereenupdating OFF but Keep EventsEnabled ON since I want the data fields to be updated.
I seemingly have to live with some delay as long as I have to add linefeeds...

Thanks!
Kai