• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Proper Use of On Error Statement

GeraldDLT

Member
Hi All,

I need your help again. I've made a On Error Statement that if there's nothing to Kill the CommandCam will run, However If you choose not to "RUN" the Cam (cancel) an Error will occur restarting the Excel itself. Please see attached file fyr. Thank you.

Regards,
Gerald
 

Attachments

  • MyPicsWrbk.xlsm
    145.4 KB · Views: 3
Code:
    Private Sub SnapshotButton_Click()
On Error GoTo picdirect:
Dim retval

    ' Make sure the current directory is set to the one
    ' where the Excel file is saved
    ChDir (ActiveWorkbook.Path)

    ' First, delete image file if present
    Kill ("image.bmp")
     
    ' Now, wait until image file is definitely gone
    While Dir("image.bmp") > ""
    Wend
     
    ' Capture new image

picdirect:
runcmdcam


     
    ' Wait until image file is definitely there
    While Dir("image.bmp") = ""
    Wend
     
    ' Short delay to let new file finish saving
    Application.Wait (Now + TimeValue("00:00:01"))
     
    ' Load new image into image object on spreadsheet
    Image1.Picture = LoadPicture("image.bmp")

    End Sub
 
Code:
Sub runcmdcam()
'
' runcmdcam Macro
'

'
ShtCmdCam.Activate
    ActiveSheet.Shapes.Range(Array("Object 1")).Select
    Selection.Verb Verb:=xlPrimary

End Sub
 
Back
Top