Performance / Velocity is bad

B

Bernd

I have a For ... Next loop in VBA which changes the text of over 1000 Shapes
(TextShapes).
The time for that is about 13 seconds.
My processor is working with 25%.

Is it possible to save time?

Some commands I tried (before the For-Next-Loop), but it is not faster:
Application.PurgeUndo
Application.UndoEnabled = False

Application.ScreenUpdating = False
Application.ShowChanges = False

Application.ShowProgress = False

Application.DeferRecalc = False
Application.LiveDynamics = False
 
B

Bernd

Hello Al Edlund,

here the extraction of VBA:

For i = 1 To UBound(Komma_Shapes_ID)


ThisDocument.Pages(Komma_Shapes_Pages(i)).Shapes.ItemFromID(Komma_Shapes_ID(i)).Text = Komma_Shapes_Inhalt(i)

Next i
 
B

Bernd

Yes, I realize.
in the String-Vector ...
....1. Komma_Shapes_Pages(i) there is the page of the shape
....2. Komma_Shapes_ID(i) there is the ID of the shape
....3. Komma_Shapes_Inhalt(i) there is the new text content for the shape

The first and the second vector I compute at the start of the document (only
one-time). The time for that is not important for me.
Before the loop the content of the third string vector is computing.
The time for that is not more then 1 second.

The problem is the loop (about 13seconds). This operation is often doing by
user.
Loop:
For i = 1 To UBound(Komma_Shapes_ID)
ThisDocument.Pages(Komma_Shapes_Pages(i)).Shapes.ItemFromID(Komma_Shapes_ID(i)).Text = Komma_Shapes_Inhalt(i)
Next i
 
A

AlEdlund

At a minimum I'd suggest you consider two loops

dim intPage as integer
dim intShape as integer

for intPage = 1 to page count
for intShape to shapes on page count
next intshape
next intpage

al
 
B

Bernd

No, I don't need this. All the Information which pages and which shapes
should change are in the 2 string vectors
1. Komma_Shapes_Pages()
2. Komma_Shapes_ID()

REDUCED example:
' -------------------------------------------------
'Shapes on Page 1:
Komma_Shapes_Pages(1) = 1
Komma_Shapes_ID(1) = 1

Komma_Shapes_Pages(2) = 1
Komma_Shapes_ID(2) = 2
....
....
'Shapes on page 2:
Komma_Shapes_Pages(800) = 2
Komma_Shapes_ID(800) = 1
....
....
-----------------------------------------------------

I don't like a loop over all pages/shapes, because only ca. 5% of all shapes
should
be changed.

The background is a process flow diagramm with some (over 1000) text shapes
with the values of the measurements of the process. The user can read a data
set of measurements from the DB for these shapes. There are many other shapes
like a pipe or a vessel which are static and never change.
 
A

AlEdlund

The reason I was suggesting that you move to two loops was to reduce the
amount of time that Visio has to spend moving back and forth between
pages, since I don't know if you sort the pages array.
al
 
B

Bernd

Yes, the pages array is sorted (Komma_Shapes_Pages()).
There are no unnecessary moves between the pages.
Have You an advise to faster the procedure?
 
A

AlEdlund

Based on that it sounds like you already have done what needs to be
accomplished,
:-(
al
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top