yzx99

导航

 

用朋友教的新方法導到EXCEL,一直出錯,出錯提示“Invalid procedure call or argument”。
查了近1個小時,才想到RS的光標位置默認是服務端,應改為服務端
代碼發下:
Dim xlApp       As Excel.Application
Dim xlWrk       As Excel.Workbook
Dim xlSht       As Excel.Worksheet
Dim xlQuery     As Excel.QueryTable
    Set xlApp = CreateObject("Excel.Application")
    xlApp.Visible = True
    Set xlWrk = xlApp.Workbooks.Add
    Rs.CursorLocation = adUseClient   '增加的一行
    Rs.Open "select * from V_O96GZDC", _
            Conn, adOpenKeyset, adLockReadOnly
    Set xlQuery = xlWrk.Sheets(1).QueryTables.Add _
                  (Rs, xlWrk.Sheets(1).Range("A1"))
    xlQuery.Refresh
    Rs.Close
    
    Set xlQuery = Nothing  '"交還控制給Excel
    Set xlWrk = Nothing
    Set xlApp = Nothing

posted on 2005-05-30 09:08  yzx99  阅读(651)  评论(0编辑  收藏  举报