Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Insert Photo - error on cancel

Hi,

I have the following code for a picture box to load an image file:

Private Sub Image1_Click()

FileToOpen = Application.GetOpenFilename("All Files
(*.jpg),*.jpg,(*.bmp),*.bmp")
Worksheets("Sheet1").OLEObjects("Image1").Object.P icture _
= LoadPicture(FileToOpen)

End Sub

which works fine unless I click "cancel" instead of selecting an image file,
at which point there is an error.

How to I allow the process to abort cleanly on "cancel"?

Thanks!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Insert Photo - error on cancel

Hi:

You need to check the cancel button on return from getting the file name. Try:

Private Sub Image1_Click()

FileToOpen = Application.GetOpenFilename( _
"All Files (*.jpg),*.jpg,(*.bmp),*.bmp")
If FileToOpen < False Then
Worksheets("Sheet1").OLEObjects("Image1").Object.P icture _
= LoadPicture(FileToOpen)
End If

End Sub
--
Hope this helps
Martin Fishlock, www.nyfconsultants.com
Please do not forget to rate this reply.


"mooresk257" wrote:

Hi,

I have the following code for a picture box to load an image file:

Private Sub Image1_Click()

FileToOpen = Application.GetOpenFilename("All Files
(*.jpg),*.jpg,(*.bmp),*.bmp")
Worksheets("Sheet1").OLEObjects("Image1").Object.P icture _
= LoadPicture(FileToOpen)

End Sub

which works fine unless I click "cancel" instead of selecting an image file,
at which point there is an error.

How to I allow the process to abort cleanly on "cancel"?

Thanks!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Insert Photo - error on cancel

Thanks - that's much cleaner code than what I had come up with!

"Martin Fishlock" wrote:

Hi:

You need to check the cancel button on return from getting the file name. Try:

Private Sub Image1_Click()

FileToOpen = Application.GetOpenFilename( _
"All Files (*.jpg),*.jpg,(*.bmp),*.bmp")
If FileToOpen < False Then
Worksheets("Sheet1").OLEObjects("Image1").Object.P icture _
= LoadPicture(FileToOpen)
End If

End Sub
--
Hope this helps
Martin Fishlock, www.nyfconsultants.com
Please do not forget to rate this reply.


"mooresk257" wrote:

Hi,

I have the following code for a picture box to load an image file:

Private Sub Image1_Click()

FileToOpen = Application.GetOpenFilename("All Files
(*.jpg),*.jpg,(*.bmp),*.bmp")
Worksheets("Sheet1").OLEObjects("Image1").Object.P icture _
= LoadPicture(FileToOpen)

End Sub

which works fine unless I click "cancel" instead of selecting an image file,
at which point there is an error.

How to I allow the process to abort cleanly on "cancel"?

Thanks!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I insert a photo into a specific cell? Artemis Bob Excel Discussion (Misc queries) 4 May 16th 10 09:27 AM
Help- Insert text if photo file not available Stevep4 Excel Discussion (Misc queries) 6 January 23rd 09 04:34 PM
Insert Photo - help Stevep4 Excel Discussion (Misc queries) 1 January 17th 09 12:59 AM
How to insert a photo in the background for printing. HoganD87 Excel Discussion (Misc queries) 1 August 20th 07 09:24 PM
Looping to insert photo Akader Excel Programming 8 February 28th 07 07:19 AM


All times are GMT +1. The time now is 10:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"