Solved

Visio: Problem inserting linfeed in Shape.Text using vba

Posted on 2014-04-28
5
784 Views
Last Modified: 2014-04-29
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
0
Comment
Question by:Lupo09
5 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 167 total points
ID: 40027089
HI,

What is the performance with

Application.ScreenUpdating = False
' Your code
Application.ScreenUpdating = True

Open in new window

Regards
0
 
LVL 19

Assisted Solution

by:regmigrant
regmigrant earned 167 total points
ID: 40027117
update: - Crossed with Rgonzo

I tried your code and initially I could reproduce the same behaviour - seeing significant differences  with crlf and without. I turned off live preview (under options) it the time reduced for both however when I turned live preview back on it stayed the same so I can't say I've definitely solved/proved it.

I would suggest that its something to do with screen updating though so try

Visio.Application.ScreenUpdating = false
  your code
Visio.Application.ScreenUpdating = True


if you haven't already
0
 

Author Comment

by:Lupo09
ID: 40027835
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?
0
 
LVL 11

Assisted Solution

by:Visio_Guy
Visio_Guy earned 166 total points
ID: 40028870
You might even try Visio.Application.EventsEnabled = False/True. I think this turns off ALL notifications to ALL add-ins, so be sure to turn it on.

The OrgChart solution has an add-in that is watching users type so that it can synchronize text with the values in Shape Data fields. This is set up as "one value per line", so I can see why the carriage returns might cause Visio to slow down.

Two-way synchronization between text and shape data fields is not natural behavior. If you are depending on it, and you turn off EventsEnabled, then you might have text/fields that are out of synch. So your code might want to set both the text of the shape and the data values.
0
 

Author Closing Comment

by:Lupo09
ID: 40029437
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
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Periodically someone asks me whether there’s a way to automatically convert all of the pages in a Visio drawing to PowerPoint slides. There have even been a few times when I’ve wanted to do that myself but I never really had enough incentive to figu…
David Parker’s latest book, Microsoft Visio 2010: Business Process Diagramming and Validation, will give you the tools to turn flowcharts and other business diagrams into valuable, data-driven corporate assets. Armed with the knowledge you’ll gain f…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now