Solved

Visio: Problem inserting linfeed in Shape.Text using vba

Posted on 2014-04-28
5
826 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Suggested Solutions

Title # Comments Views Activity
Visio 2013 - How to set the default save directory 1 1,224
Extract Embeded visio objects 3 76
visio file 1 90
Struggling with a Value Not Refreshing in Shapesheet 6 62
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 …
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…
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…

749 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