How to print filenames under pictures

D

Doug Robbins - Word MVP

I created this yesterday for someone else who posted with a similar request
to the drawing.graphics newsgroup

The following code will display a dialog in which you can select the folder
that contains the picture files and then it will insert each of the pictures
into a document with the filename of each following the picture

Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim myrange As Range
'Select the folder that contains the files
With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
PathToUse = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With
'Close all open documents before beginning
Documents.Close SaveChanges:=wdPromptToSaveChanges
'Get the new title to be used for each document
Documents.Add
myFile = Dir(PathToUse & "*.*")
While myFile <> ""
With ActiveDocument
Set myrange = .Range
myrange.Collapse wdCollapseEnd
.InlineShapes.AddPicture PathToUse & myFile, , , myrange
Set myrange = .Range
myrange.Collapse wdCollapseEnd
myrange.InsertAfter vbCr & myFile & vbCr
End With
myFile = Dir()
Wend


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
R

Roy Johnston

Doug Robbins - Word MVP said:
I created this yesterday for someone else who posted with a similar request
to the drawing.graphics newsgroup

The following code will display a dialog in which you can select the folder
that contains the picture files and then it will insert each of the pictures
into a document with the filename of each following the picture

Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim myrange As Range
'Select the folder that contains the files
With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
PathToUse = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With
'Close all open documents before beginning
Documents.Close SaveChanges:=wdPromptToSaveChanges
'Get the new title to be used for each document
Documents.Add
myFile = Dir(PathToUse & "*.*")
While myFile <> ""
With ActiveDocument
Set myrange = .Range
myrange.Collapse wdCollapseEnd
.InlineShapes.AddPicture PathToUse & myFile, , , myrange
Set myrange = .Range
myrange.Collapse wdCollapseEnd
myrange.InsertAfter vbCr & myFile & vbCr
End With
myFile = Dir()
Wend


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com


Thank you for your reply to my problem. I'm a computor idiot because I have no idea what to do with the information that you gave me. Where do I start with this information?
 

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