Dialog Box - User hits cancel

  • Thread starter Thread starter Michael Hopwood
  • Start date Start date
I have a dialog box for inserting an image that pops up in my macro - if the
user presses cancel - an error is reported (method not supported) how can I
suppress this error?

Can I use some code like - if cancel is pressed exit sub?

Thanks,

Colin
 
Here is my code....

Sub InsertPictures()

Application.ScreenUpdating = False

Range("F3").Select
Application.Dialogs(xlDialogInsertPicture).Show
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 225#
Selection.ShapeRange.Width = 300#


Range("F23").Select
Application.Dialogs(xlDialogInsertPicture).Show
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 225#
Selection.ShapeRange.Width = 300#

Application.ScreenUpdating = True

ActiveWorkbook.Close (True)

End Sub
 
Range("F3").Select
If Application.Dialogs(xlDialogInsertPicture).Show Then
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 225#
Selection.ShapeRange.Width = 300#
End If

Range("F23").Select
If Application.Dialogs(xlDialogInsertPicture).Show Then
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 225#
Selection.ShapeRange.Width = 300#
End If

The dialog returns false if the user presses cancel.
 
Worked a treat - thanks!

Colin

Tom Ogilvy said:
Range("F3").Select
If Application.Dialogs(xlDialogInsertPicture).Show Then
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 225#
Selection.ShapeRange.Width = 300#
End If

Range("F23").Select
If Application.Dialogs(xlDialogInsertPicture).Show Then
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 225#
Selection.ShapeRange.Width = 300#
End If

The dialog returns false if the user presses cancel.

--
Regards,
Tom Ogilvy



macro -
if
 
Back
Top