Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2006

Tip: Looking for answers? Try searching our database.

VB to Insert Thumbnails

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
T. Jenkins - 11 Feb 2006 22:07 GMT
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. Jenkins - 11 Feb 2006 22:46 GMT
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

> 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
[quoted text clipped - 15 lines]
>
> Todd
Helmut Weber - 11 Feb 2006 23:24 GMT
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))

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

T. Jenkins - 12 Feb 2006 13:13 GMT
Thanks, Helmut.  That worked perfectly.

Todd

> Hi Todd,
>
[quoted text clipped - 12 lines]
>
> ..FoundFiles(i) = JustName(.FoundFiles(i))
Jay Freedman - 12 Feb 2006 15:15 GMT
>Hi Todd,
>
[quoted text clipped - 12 lines]
>
>.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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.