Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How to insert an image file into Work AND have the file name displ
I need to insert a number of image files into Word, and for each image, I
need the file name to display below the image. Any ideas? Cheers Marc |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How to insert an image file into Work AND have the file name displ
Hi Marc,
There's nothing built-in to do that, but a macro would be easy. You haven't given much detail about how you want this formatted, so this macro should be considered just a first draft that you can tweak to get what you want. See http://www.gmayor.com/installing_macro.htm if needed. Sub InsertPictureAndFileName() Dim FileName As String Dim dlg As Dialog Set dlg = Dialogs(wdDialogInsertPicture) If dlg.Show = -1 Then FileName = dlg.Name End If If FileName = "" Then Exit Sub ' canceled Selection.InsertAfter vbCr & FileName Selection.Collapse wdCollapseEnd End Sub -- 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. On Wed, 3 May 2006 17:08:02 -0700, Marc C wrote: I need to insert a number of image files into Word, and for each image, I need the file name to display below the image. Any ideas? Cheers Marc |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How to insert an image file into Work AND have the file name d
Thank you very much for that Jay.
I got it to work - and now I want to ask if you could help me tweak it? Is it possible to make 3 enhancements to the macro: - only insert the file name into Word (as opposed to the file name and the folder reference) - add the file name to multiple images that I select for inserting into the document (currently, if I select multiple images, it only brings the file reference of the first image selected in the group) - when inserting the images, is it possible to control the size (height & width) of the images - could default to say 1.5cm x 1.5cm. If this needs to be a separate macro - no problem. You are helping me more than you know - thanks in anticipation. Regards Marc "Jay Freedman" wrote: Hi Marc, There's nothing built-in to do that, but a macro would be easy. You haven't given much detail about how you want this formatted, so this macro should be considered just a first draft that you can tweak to get what you want. See http://www.gmayor.com/installing_macro.htm if needed. Sub InsertPictureAndFileName() Dim FileName As String Dim dlg As Dialog Set dlg = Dialogs(wdDialogInsertPicture) If dlg.Show = -1 Then FileName = dlg.Name End If If FileName = "" Then Exit Sub ' canceled Selection.InsertAfter vbCr & FileName Selection.Collapse wdCollapseEnd End Sub -- 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. On Wed, 3 May 2006 17:08:02 -0700, Marc C wrote: I need to insert a number of image files into Word, and for each image, I need the file name to display below the image. Any ideas? Cheers Marc |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How to insert an image file into Work AND have the file name d
Hi Marc,
The first enhancement is simple. Replace the line Selection.InsertAfter vbCr & FileName with this line: Selection.InsertAfter vbCr & WordBasic.FileNameInfo(FileName, 3) The second request isn't possible, for two reasons: First, the dialog gives the macro only the last filename of the multiple selections. There's nothing the macro can do to find out what the others were. Second, even when you aren't using the macro but just the Insert Picture From File dialog, multiple-selected pictures don't get inserted in the document in the same order as they appear in the dialog -- the last chosen picture appears first, and then the rest come in. That doesn't seem like a useful feature. Stick to inserting one at a time. Assign the macro to a toolbar button or a keyboard shortcut to make it easier to start it. It would be possible to make the macro size the picture, but that takes a bit more work than I can do tonight. I may be able to whip something up tomorrow. In the meantime, or instead, it's better to use a table to control the sizing. Set the column width, click Table AutoFit Fixed Column Width, and press Ctrl+Alt+U to turn off the table borders. Put the cursor in a cell, run the macro, tab to the next cell, run the macro, etc. The picture will be forced to the width of the cell, and the height will be adjusted proportionally. -- 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. On Wed, 3 May 2006 18:39:01 -0700, Marc C wrote: Thank you very much for that Jay. I got it to work - and now I want to ask if you could help me tweak it? Is it possible to make 3 enhancements to the macro: - only insert the file name into Word (as opposed to the file name and the folder reference) - add the file name to multiple images that I select for inserting into the document (currently, if I select multiple images, it only brings the file reference of the first image selected in the group) - when inserting the images, is it possible to control the size (height & width) of the images - could default to say 1.5cm x 1.5cm. If this needs to be a separate macro - no problem. You are helping me more than you know - thanks in anticipation. Regards Marc "Jay Freedman" wrote: Hi Marc, There's nothing built-in to do that, but a macro would be easy. You haven't given much detail about how you want this formatted, so this macro should be considered just a first draft that you can tweak to get what you want. See http://www.gmayor.com/installing_macro.htm if needed. Sub InsertPictureAndFileName() Dim FileName As String Dim dlg As Dialog Set dlg = Dialogs(wdDialogInsertPicture) If dlg.Show = -1 Then FileName = dlg.Name End If If FileName = "" Then Exit Sub ' canceled Selection.InsertAfter vbCr & FileName Selection.Collapse wdCollapseEnd End Sub -- 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. On Wed, 3 May 2006 17:08:02 -0700, Marc C wrote: I need to insert a number of image files into Word, and for each image, I need the file name to display below the image. Any ideas? Cheers Marc |
#5
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How to insert an image file into Work AND have the file name d
Hi Jay
Thanks again so much. That all works fine now and the table is absolutely fine for sizing the image. I really appreciate your efforts. Regards Marc "Jay Freedman" wrote: Hi Marc, The first enhancement is simple. Replace the line Selection.InsertAfter vbCr & FileName with this line: Selection.InsertAfter vbCr & WordBasic.FileNameInfo(FileName, 3) The second request isn't possible, for two reasons: First, the dialog gives the macro only the last filename of the multiple selections. There's nothing the macro can do to find out what the others were. Second, even when you aren't using the macro but just the Insert Picture From File dialog, multiple-selected pictures don't get inserted in the document in the same order as they appear in the dialog -- the last chosen picture appears first, and then the rest come in. That doesn't seem like a useful feature. Stick to inserting one at a time. Assign the macro to a toolbar button or a keyboard shortcut to make it easier to start it. It would be possible to make the macro size the picture, but that takes a bit more work than I can do tonight. I may be able to whip something up tomorrow. In the meantime, or instead, it's better to use a table to control the sizing. Set the column width, click Table AutoFit Fixed Column Width, and press Ctrl+Alt+U to turn off the table borders. Put the cursor in a cell, run the macro, tab to the next cell, run the macro, etc. The picture will be forced to the width of the cell, and the height will be adjusted proportionally. -- 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. On Wed, 3 May 2006 18:39:01 -0700, Marc C wrote: Thank you very much for that Jay. I got it to work - and now I want to ask if you could help me tweak it? Is it possible to make 3 enhancements to the macro: - only insert the file name into Word (as opposed to the file name and the folder reference) - add the file name to multiple images that I select for inserting into the document (currently, if I select multiple images, it only brings the file reference of the first image selected in the group) - when inserting the images, is it possible to control the size (height & width) of the images - could default to say 1.5cm x 1.5cm. If this needs to be a separate macro - no problem. You are helping me more than you know - thanks in anticipation. Regards Marc "Jay Freedman" wrote: Hi Marc, There's nothing built-in to do that, but a macro would be easy. You haven't given much detail about how you want this formatted, so this macro should be considered just a first draft that you can tweak to get what you want. See http://www.gmayor.com/installing_macro.htm if needed. Sub InsertPictureAndFileName() Dim FileName As String Dim dlg As Dialog Set dlg = Dialogs(wdDialogInsertPicture) If dlg.Show = -1 Then FileName = dlg.Name End If If FileName = "" Then Exit Sub ' canceled Selection.InsertAfter vbCr & FileName Selection.Collapse wdCollapseEnd End Sub -- 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. On Wed, 3 May 2006 17:08:02 -0700, Marc C wrote: I need to insert a number of image files into Word, and for each image, I need the file name to display below the image. Any ideas? Cheers Marc |
#6
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How to insert an image file into Work AND have the file name d
Hi Marc,
In addition to the code Jay gave you, if the existing images were inserted as linked images, then getting source filename is fairly straightforward. For example: Sub GetPicNames() Dim i As Integer Dim j As Integer Dim PicName As String With ActiveDocument For i = 1 To .InlineShapes.Count If Not .InlineShapes(i).LinkFormat Is Nothing Then PicName = .InlineShapes(i).LinkFormat.SourceName .InlineShapes(i).Range.InsertAfter (PicName) End If Next For j = 1 To .Shapes.Count If Not .Shapes(j).LinkFormat Is Nothing Then PicName = .Shapes(j).LinkFormat.SourceName .Shapes(j).Anchor.InsertAfter (PicName) End If Next End With End Sub Cheers "Marc C" wrote in message ... Thank you very much for that Jay. I got it to work - and now I want to ask if you could help me tweak it? Is it possible to make 3 enhancements to the macro: - only insert the file name into Word (as opposed to the file name and the folder reference) - add the file name to multiple images that I select for inserting into the document (currently, if I select multiple images, it only brings the file reference of the first image selected in the group) - when inserting the images, is it possible to control the size (height & width) of the images - could default to say 1.5cm x 1.5cm. If this needs to be a separate macro - no problem. You are helping me more than you know - thanks in anticipation. Regards Marc "Jay Freedman" wrote: Hi Marc, There's nothing built-in to do that, but a macro would be easy. You haven't given much detail about how you want this formatted, so this macro should be considered just a first draft that you can tweak to get what you want. See http://www.gmayor.com/installing_macro.htm if needed. Sub InsertPictureAndFileName() Dim FileName As String Dim dlg As Dialog Set dlg = Dialogs(wdDialogInsertPicture) If dlg.Show = -1 Then FileName = dlg.Name End If If FileName = "" Then Exit Sub ' canceled Selection.InsertAfter vbCr & FileName Selection.Collapse wdCollapseEnd End Sub -- 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. On Wed, 3 May 2006 17:08:02 -0700, Marc C wrote: I need to insert a number of image files into Word, and for each image, I need the file name to display below the image. Any ideas? Cheers Marc |
#7
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
How to insert an image file into Work AND have the file name d
Thanks Macropod - I really appreciate your input.
Regards Marc "macropod" wrote: Hi Marc, In addition to the code Jay gave you, if the existing images were inserted as linked images, then getting source filename is fairly straightforward. For example: Sub GetPicNames() Dim i As Integer Dim j As Integer Dim PicName As String With ActiveDocument For i = 1 To .InlineShapes.Count If Not .InlineShapes(i).LinkFormat Is Nothing Then PicName = .InlineShapes(i).LinkFormat.SourceName .InlineShapes(i).Range.InsertAfter (PicName) End If Next For j = 1 To .Shapes.Count If Not .Shapes(j).LinkFormat Is Nothing Then PicName = .Shapes(j).LinkFormat.SourceName .Shapes(j).Anchor.InsertAfter (PicName) End If Next End With End Sub Cheers "Marc C" wrote in message ... Thank you very much for that Jay. I got it to work - and now I want to ask if you could help me tweak it? Is it possible to make 3 enhancements to the macro: - only insert the file name into Word (as opposed to the file name and the folder reference) - add the file name to multiple images that I select for inserting into the document (currently, if I select multiple images, it only brings the file reference of the first image selected in the group) - when inserting the images, is it possible to control the size (height & width) of the images - could default to say 1.5cm x 1.5cm. If this needs to be a separate macro - no problem. You are helping me more than you know - thanks in anticipation. Regards Marc "Jay Freedman" wrote: Hi Marc, There's nothing built-in to do that, but a macro would be easy. You haven't given much detail about how you want this formatted, so this macro should be considered just a first draft that you can tweak to get what you want. See http://www.gmayor.com/installing_macro.htm if needed. Sub InsertPictureAndFileName() Dim FileName As String Dim dlg As Dialog Set dlg = Dialogs(wdDialogInsertPicture) If dlg.Show = -1 Then FileName = dlg.Name End If If FileName = "" Then Exit Sub ' canceled Selection.InsertAfter vbCr & FileName Selection.Collapse wdCollapseEnd End Sub -- 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. On Wed, 3 May 2006 17:08:02 -0700, Marc C wrote: I need to insert a number of image files into Word, and for each image, I need the file name to display below the image. Any ideas? Cheers Marc |