Solved

Visio: Problem inserting linfeed in Shape.Text using vba

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The Question Several times in recent years, someone has posted a question at EE asking whether they could display the Windows directory structure – folders and subfolders – using Visio. When one person specifically asked about displaying directory …
The ability to add structure to Visio diagrams using containers, lists and callouts is one of my favorite features in Visio 2010. In this article I’ll describe a mashup of containers and lists that meet a real-world need. Prior to reading this ar…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

919 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

13 Experts available now in Live!

Get 1:1 Help Now