routine doesn't count correctly

T

Tony Logan

I'm inserting PowerPoint slides into a Word document. Everything runs fine
until the total # of PowerPoint slides is 100 or more (I know what you're
asking...who's going to sit through a 100-slide PowerPoint presentation? This
question haunts me, too.).

With 100+ slides, the order of slide insertion goes correctly from slides 1
through 10. But then things go haywire. Slides 100-109 get inserted next,
then we go back to 11 and continue from there.

Here's the code. I'm not sure what's wrong with the logic:

Dim pics As Integer
Dim JPGFolder As Folder
Dim JPGFile As File

pics = 0
For Each JPGFile In JPGFolder.Files
pics = pics + 1 ' count pics; use this info later in routine
Selection.InlineShapes.AddPicture FileName:=(JPGFile)
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Collapse Direction:=wdCollapseEnd
Next JPGFile
 
J

Jonathan West

Is is actually the wrong slides that are being inserted? Is it possible that
the page numbers are being truncated in their frame?
 
T

Tony Logan

Hi, Jonathan. It's actually the wrong slide. I'm checking the value of
JPGFile as I step through the code. The values go from 1 to 10, then 100-109,
then 11. I keep thinking I've made a logic error, but I don't know where or
what it is.
 
J

Jean-Guy Marcil

Tony Logan was telling us:
Tony Logan nous racontait que :
I'm inserting PowerPoint slides into a Word document. Everything runs
fine until the total # of PowerPoint slides is 100 or more (I know
what you're asking...who's going to sit through a 100-slide
PowerPoint presentation? This question haunts me, too.).

With 100+ slides, the order of slide insertion goes correctly from
slides 1 through 10. But then things go haywire. Slides 100-109 get
inserted next, then we go back to 11 and continue from there.

Here's the code. I'm not sure what's wrong with the logic:

Dim pics As Integer
Dim JPGFolder As Folder
Dim JPGFile As File

pics = 0
For Each JPGFile In JPGFolder.Files
pics = pics + 1 ' count pics; use this info later in routine
Selection.InlineShapes.AddPicture FileName:=(JPGFile)
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Collapse Direction:=wdCollapseEnd
Next JPGFile

Have checked out your Folder?
Your files are probably named according to a numbering schemes, so that when
they are listed, even in Explorer, you get 1 to 10, then 100 to 109, then
11...

Your code is just picking them up in that order.

To avoid any potential problems, when creating the JPG files, prefix all
numbers with an appropriate number of "0":

001
002
003
004
005
006
007
008
009
010
011
....
100
101
102
etc.


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jonathan West

Tony Logan said:
Hi, Jonathan. It's actually the wrong slide. I'm checking the value of
JPGFile as I step through the code. The values go from 1 to 10, then
100-109,
then 11. I keep thinking I've made a logic error, but I don't know where
or
what it is.

Ah. I see it. The slides are being sorted alphabetically by filename, not
numerically.
 
D

Dave Lett

Tony,

If you have a lot of images, you can rename your files by using the Name
Statement.

Name oldpathname As newpathname

See the VBA Help File topic Name Statement if you need more detailed
information.

HTH,
Dave
 

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