Sub manual()
'------------------------------------------------------------------
Application.ScreenUpdating = False
    Dim res As Worksheet
    Dim ss As String   '------------ use CSDB directly
    Dim bdate As String
    Dim edate As String
    Sheets("ETCH").Activate
    Set res = Sheets("ETCH").Sheets1
    res.Cells.Range("A:V").ClearContents
    
    bdate = Sheets("eap").TextBox1.Text
    edate = Sheets("eap").TextBox2.TextSql = "  select lotid,lottype,evtime,evvariant,partname,evuser from hist_lotevents@odsprd"
Sql = Sql & "   where evvariant in ('AEPE01','AEPE02','AENE01','AEME01','AEME02','AEOE01','AEOE02','AEAS01','AEAS02','AWCL01','AWCL03','AWME01','AWST01','AWNR01','AWSE01','AEUV01')"
Sql = Sql & "   and evtype='NTKI'"
Sql = Sql & "   and fun_get_histlotevents_cmt(lotid,evtime) not like '%RUN=A%'"
Sql = Sql & "   and evtime>=to_date(' " & bdate & " ', 'YYYY-MM-DD')"
Sql = Sql & "   and evtime<to_date(' " & edate & " ', 'YYYY-MM-DD'))"ss = "ODBC;DSN=MFGPRD;UID=rptprd;PWD=mfgrptprd;server=MFGPRD"    With ActiveSheet.QueryTables.Add(Connection:=ss, Destination:=Worksheets("ETCH").Range("A1"), Sql:=Sql)
            .BackgroundQuery = False
            .Refresh
    End With
    
    End Sub
以上颜色地方  下标出界    解释下

解决方案 »

  1.   

    "ETCH" 是工作薄名吧,不像是工作表名。
      

  2.   

     Sheets("ETCH").Activate 
        Set res = Sheets("ETCH").Sheets1 
    先后顺序颠倒了,
    Set res = Sheets("ETCH").Sheets1 
    Sheets("ETCH").Activate 
    试一试
      

  3.   

    你确定你的工作簿有 "ETCH" 这个工作表,并且前后没有空格?
      

  4.   

    我这样没有问题
    检查你的sheet是否有ETCH命名,是否有拼写错误Sub manual()
    '------------------------------------------------------------------
    Application.ScreenUpdating = False
        Dim res As Worksheet
        Dim ss As String  '------------ use CSDB directly
        Dim bdate As String
        Dim edate As String
        
        Sheets("ETCH").Activate
        Cells(1, 1) = "ok"
        
        End Sub