Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Suppressing Word dialogue box warning when cancel button pressed

Status
Not open for further replies.

NIA2

Technical User
Aug 30, 2006
137
AU
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:


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.
 
Code:
...
    With dlg
        .AllowMultiSelect = False       'Make single selection only
        If .Show() <> 0 Then
            strFilePath = .SelectedItems(1)
        Else
            Exit Sub
        End If
    End With
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Fantastic - works perfectly,

thanks so much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top