VB to Insert Thumbnails

T

T. Jenkins

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.

Todd
 
T

T. Jenkins

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
Else
MsgBox "There were no files found."
End If
End With

==================

Thanks,
Todd
 
H

Helmut Weber

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

sample:

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

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Jay Freedman

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

sample:

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

Another way (not better, just different):

Public Function JustName2(sTmp As String) As String
On Error Resume Next
sTmp = WordBasic.FileNameInfo$(sTmp, 3)
JustName2 = sTmp
End Function

Sub test009124()
MsgBox JustName2("c:\test\word\Myfile.doc")
End Sub

The FileNameInfo$ function is a leftover from old WordBasic; see
http://www.word.mvps.org/FAQs/MacrosVBA/WordBasicCommands.htm for
documentation.

A disadvantage of this function is that it throws a "path not found"
error if the filename passed to it doesn't belong to an existing file,
so it requires an error trap.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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