Hi All,
I have the following field code inserted into a textbox in a Word file:
{MACROBUTTON GetImage "Double-click to insert image"}
...that when double clicked runs the code below which opens a dialogue box so the user can navigate to a directory and insert an image:
Everything works really well except that if the user presses the cancel button in the dialogue, a generic Visual Basic dialogue box appears saying:
This is not a valid file name: Try one or more of the following:
- check the path to make sure it was typed correctly
- Select a file from the list of files and folders
OK Help
I don't really want anything like this appearing at all if the cancel button is pressed, so I wondered if there was a way to suppress this warning and just allow them cancel if they want to?
Any help much appreciated.
I have the following field code inserted into a textbox in a Word file:
{MACROBUTTON GetImage "Double-click to insert image"}
...that when double clicked runs the code below which opens a dialogue box so the user can navigate to a directory and insert an image:
Code:
Sub GetImage()
Dim dlg As Office.FileDialog
Dim strFilePath As String
Set dlg = Application.FileDialog(msoFileDialogFilePicker)
With dlg
.AllowMultiSelect = False 'Make single selection only
If .Show() <> 0 Then
strFilePath = .SelectedItems(1)
End If
End With
Selection.InlineShapes.AddPicture FileName:= _
strFilePath, LinkToFile:=False, _
SaveWithDocument:=True
End Sub
Everything works really well except that if the user presses the cancel button in the dialogue, a generic Visual Basic dialogue box appears saying:
This is not a valid file name: Try one or more of the following:
- check the path to make sure it was typed correctly
- Select a file from the list of files and folders
OK Help
I don't really want anything like this appearing at all if the cancel button is pressed, so I wondered if there was a way to suppress this warning and just allow them cancel if they want to?
Any help much appreciated.