Access VBA: Is it possible to reset error handling

前端 未结 5 1289
再見小時候
再見小時候 2021-02-19 05:18

I am using in the first part of my program

on error go to start

Suppose in my second part I am again using

on error resume next

This second erro

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-19 05:50

    It is nearly always better to avoid errors, rather than handling them. For example:

    Set objexcel = CreateObject("excel.Application")
    objexcel.Visible = True
    
    'On Error GoTo Openwb '
    'wbExists = False '
    
    If Dir("C:\REPORT3.xls") = "" Then
        objexcel.Workbooks.Add
        Set wbexcel = objexcel.ActiveWorkbook
        Set objSht = wbexcel.Worksheets("Sheet1")
    Else
        Set wbexcel = objexcel.Workbooks.Open("C:\REPORT3.xls")
        Set objSht = wbexcel.Worksheets("Sheet1")
    End If
    
    objSht.Activate
    'wbExists = True '
    

提交回复
热议问题