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

RE: VB to Insert Thumbnails by TJenkins

TJenkins
Sat Feb 11 16:46:28 CST 2006


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

"T. Jenkins" wrote:

>
> 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
>

Re: VB to Insert Thumbnails by Helmut

Helmut
Sat Feb 11 17:24:38 CST 2006

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"

Re: VB to Insert Thumbnails by TJenkins

TJenkins
Sun Feb 12 07:13:27 CST 2006

Thanks, Helmut. That worked perfectly.

Todd


"Helmut Weber" wrote:

> 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"
>

Re: VB to Insert Thumbnails by Jay

Jay
Sun Feb 12 09:15:51 CST 2006

On Sun, 12 Feb 2006 00:24:38 +0100, Helmut Weber
<nbhymsjxdgcn@mailinator.com> wrote:

>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 FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.