Solved

Visio: Problem inserting linfeed in Shape.Text using vba

Posted on 2014-04-28
5
811 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 49

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Meetings to discuss business process can waste time, and often do .  The meeting's dialog can get confusing when participants have different professional perspectives and backgrounds.  A jointly-developed process picture helps wade through the confu…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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