Adding Pictures and performance.

D

Doug

I have an interesting problem that I have just found.
I am running a VB script to run through an array and add pictures to a table.
The document was originally done in Word 2003 and is included in a template
file.
The VB runs fine and adds about 268 photos in less than 30 seconds.
However, when I save the template as a Word 2007 macro enable template and
run then same VB script, it takes over 4 minutes to add the same number of
photos.
Has anyone run across this before?
Any ideas as to why Word 2003 and Word 2007 would handle adding pictures to
a table differently?

Thank You
Doug
 
G

Graham Mayor

Word 2007 handles graphics differently from earlier versions and if you
insert linked images e.g. using a macro similar to the following, then Word
2007 is indeed very much slower than Word 2003 to insert those omages.
However if you change LinkToFile:=True to False, there is not much
difference in the speed of the two applications.

On a fairly old PC with a data sample of 230 images, the slower merges took
around 2 minutes to complete.

You may find it slightly quicker to mail merge the graphics into the table
http://www.gmayor.com/mail_merge_graphics.htm

Dim ChangeDoc As Document, RefDoc As Document
Dim rTable As Table
Dim oPic As Range
Dim oPara As Range
Dim i As Long
Dim sFname As String

sFname = "D:\My Documents\Test\Pictures Data.doc"
Set RefDoc = ActiveDocument
Set ChangeDoc = Documents.Open(sFname)
Set rTable = RefDoc.Tables(1)
For i = 1 To ChangeDoc.Paragraphs.Count
Set oPic = ChangeDoc.Paragraphs(i).Range
oPic.End = oPic.End - 1
rTable.Cell(i, 1).Range.InlineShapes.AddPicture FileName:= _
oPic.Text, LinkToFile:=True, _
SaveWithDocument:=True
If i < ChangeDoc.Paragraphs.Count Then rTable.Rows.Add
Next i
ChangeDoc.Close wdDoNotSaveChanges


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Doug

Hi Graham, thank you for the info.
I suspect that if I link the pictures it will do what I need.
Will give it a try.
 
D

Doug

Hi Graham, have done some testing and there is still a major performance lag
in my code.
The main difference between your code and mine is I am adding the pictures
to a 3 column table.
I add the picture to the cell in the first column, then jump to the last
column and add another picture. while steping through the code there is a
definate lag when I select the 3rd column cell.
I did a test by only adding the pictures into the 1st column and it
performed OK.
So it looks more of a table issue than a graphics issue.
Note I did change the code to use linktofile:=True as you suggested and this
made no difference.
 
G

Graham Mayor

The linking only appears to affect Word 2003. With Word 2007 it makes no
difference. Similarly inserting the images alternately in columns 1 and 3 of
a three column table made no noticable difference to the speed (using the
modified version of my macro below). As I mentioned in my earlier post, Word
2007 handles images differently from earlier versions.

One thing to try is to save the document in Word 97-2003 format before
running the macro. This then allows graphics to behave as they did in Word
2003, however there will be some additional processing overhead. FWIW I
found no appreciable difference in speed running my macro in Word 2003 and
2007.


Dim ChangeDoc As Document, RefDoc As Document
Dim rTable As Table
Dim iCol As Integer
Dim oPic As Range
Dim oPara As Range
Dim i As Long
Dim sFname As String

sFname = "D:\My Documents\Test\Pictures Data.doc"
Set RefDoc = ActiveDocument
Set ChangeDoc = Documents.Open(sFname)
Set rTable = RefDoc.Tables(1)
For i = 1 To ChangeDoc.Paragraphs.Count
iCol = i Mod 2
If iCol = 0 Then iCol = 3
Set oPic = ChangeDoc.Paragraphs(i).Range
oPic.End = oPic.End - 1
rTable.Cell(i, iCol).Range.InlineShapes.AddPicture FileName:= _
oPic.Text, LinkToFile:=True, _
SaveWithDocument:=True
If i Mod 2 = 0 Then rTable.Rows.Add
Next i
ChangeDoc.Close wdDoNotSaveChanges


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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