Solved

Visio: Problem inserting linfeed in Shape.Text using vba

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

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 we’ll examine lists. We’ll explore containers and callouts in separate articles. Prior to reading th…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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