View Single Post
 
Old 05-12-2023, 04:34 AM
MartinGM MartinGM is offline Windows 11 Office 2021
Advanced Beginner
 
Join Date: May 2023
Location: England
Posts: 66
MartinGM is on a distinguished road
Default

SOLVED

OK, coming at this from a different direction, here is how I can insert a picture AND capture its filename. It is much simpler than the AltText method I used to use.

In passing, I go on to use the filename with the extension stripped off, as the picture caption in my document.

Sub InsertThumbnail()

Dim objFSO As New FileSystemObject
Dim FileName As String 'The filename of the inserted picture
Dim FullPath As String 'The fliepath of the picture to be inserted

Dim ThumbnailsFolder As String 'The folder containing the picture to be inserted

'Insert the picture, capturing the file name in the process

ThumbnailsFolder = "C:\<My Location>"

With Application.FileDialog(msoFileDialogOpen) 'Open the Thumbails folder

.InitialFileName = ThumbnailsFolder 'Set where the dialog opens
.Title = "Choose a file to insert" 'Title for the dialog box
.AllowMultiSelect = False
If .Show <> -1 Then Exit Sub
FileName = objFSO.GetFileName(.SelectedItems(1)) 'Capture the filename
FullPath = ThumbnailsFolder & FileName 'Set the full path of the picture, for later insertion

End With

Selection.InlineShapes.AddPicture FileName:=FullPath, LinkToFile:=False, _
SaveWithDocument:=True 'Insert the picture

End Sub

Last edited by MartinGM; 05-12-2023 at 09:41 AM.
Reply With Quote