VB to Insert Thumbnails

VB to Insert Thumbnails

Post by VC4gSmVua2 » Mon, 13 Feb 2006 07:07:26

I'm trying to develop a macro that will insert all images into a Word Table
to allow comments to be entered for each image. I plan to resize the images
to thumbnail size, and hope to be able to have two columns of photos, with a
comment column next to each (4 columns total).

I assume this is not too complicated, but am hoping someone can give me a
head-start. I just want something that will grab a copy of all JPEG files in
a given folder, and insert them one at a time into the table. I'm thinking
that I would got right to left, then down, so the first image would go in
cell A1 (using Excel nomenclature), the second in cell C1, the third in A2,
and so on. I assume there's a collection I could use to cycle through all
files with an exention of JPEG, right?

Can anyone give me any tips on doing this. If possible, I'd really love to
get a shell of a program that I can then tweak.

Thanks in advance for any ideas.


VB to Insert Thumbnails

Post by VC4gSmVua2 » Mon, 13 Feb 2006 07:46:28

False alarm. I found an example in the Help that allowed me to do what I
want (excerpt below). Next question, though, is how I can enter the file
name. I was able to insert the full path and filename, but I just want the
filename. Any suggestions?

========= Excerpt from code ===========

Set fs = Application.FileSearch
With fs
.LookIn = myPath
.FileName = "*.jpg"
If .Execute > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
' MsgBox .FoundFiles(i)
Selection.InlineShapes.AddPicture FileName:=.FoundFiles(i),
LinkToFile:=False, SaveWithDocument:=True
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Next i
MsgBox "There were no files found."
End If
End With




VB to Insert Thumbnails

Post by Helmut Web » Mon, 13 Feb 2006 08:24:38

Hi Todd,

like this and in other ways, too:

Public Function JustName(sTmp As String) As String
sTmp = Right(sTmp, Len(sTmp) - InStrRev(sTmp, "\"))
JustName = sTmp
End Function

Sub test009123()
MsgBox JustName("c:\test\word\Myfile.doc")
End Sub


.FoundFiles(i) = JustName(.FoundFiles(i))

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

VB to Insert Thumbnails

Post by VC4gSmVua2 » Mon, 13 Feb 2006 22:13:27

Thanks, Helmut. That worked perfectly.