How can I increment filenames

T

text news

Sorry, a bit of a beginner...

I want to be able to print a batch of pages which are all the same except
for a photo which has to be inserted . Each page has a different photo.

For example I have 5 photos called "001.jpg" to "005.jpg"
My document has a space in the top right hand corner where the photo has to
go.
The first page needs to print with photo "001.jpg" inserted.
The second page with photo "002.jpg" etc.
The only thing that changes is the photo.

I had a bit of a play and something like this seems to be part way there:
(This is embarrasing! I hope you do not injure yourself laughing!)

-----------------------------
Dim check, counter
check = True: counter = 0
Do
Do
Selection.InlineShapes.AddPicture FileName:= _
"c:\temp\001.jpg" _
, LinkToFile:=False, SaveWithDocument:=True
counter = counter + 1
If counter = 3 Then
check = False
Exit Do
End If
Loop
Loop Until check = False
------------------------------
But I have no idea how to increment the filename with each loop so that the
first time it loads 001.jpg and the second time 002.jpg etc.

If anyone can help me I shall be very grateful but please keep it dead
simple.

Many thanks
Les
 
S

Steve Lang

You are on the right track.

maybe you can use something along these lines:

Dim strCounter As String
Dim intCounter As Integer
intCounter = 1
Do Until intCounter = 4
strCounter = CStr(intCounter)
Do Until Len(strCounter) = 3
strCounter = "0" & strCounter
Loop
Selection.InlineShapes.AddPicture FileName:= _
"C:\temp\" & strCounter & ".jpg" _
, LinkToFile:=False, SaveWithDocument:=True
intCounter = intCounter + 1
Loop


HTH, and have a great day!

Steve Lang
 
T

text news

Steve you are a star, it worked, and now I have something to build on.
Not bad.... 30 mins for a reply that works, arn't newsgroups wonderful!

Very grateful

Les
 

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