热情软件屋

 

出现错误信息:实时错误 ‘1004’对象'Range'的方法'_Global'失败


编号:QA003478
建立日期: 2000年10月31日 最后修改日期:2000年10月31日
所属类别:

舒少毅:
    操作系统:NT4.0,WIN98
    编程工具:VB6.0,SQL7.0,EXCEL2000
    问题:在VB中需把后台中的表转到EXCEL,且数据量较大,具体程序如下:
    通用:
    Dim xlApp As excel.Application
    Dim xlBook As excel.Workbook
    Dim xlSheet As excel.Worksheet
    转EXCEL按钮:
    Set xlApp = CreateObject("Excel.Application")
    Set xlBook = xlApp.Workbooks.Add
    Set xlSheet = xlBook.Worksheets(1)
    With ActiveSheet.QueryTables.Add(Connection:= _
     "ODBC;DSN=Development;Description=development for material;SERVER=shoetown;UID=sa;WSID=administrators;DATABASE=development;QueryLogFile=Yes" _
     , Destination:=Range("A1"))
     .CommandText = Array( _
     "SELECT ColorCode, ColorDescription,Chinese, LongAbbrv, Remark" & Chr(13) & "" & Chr(10) & "FROM development.dbo.tblNcs order by ColorCode" _
     )
     .Name = "查询来自 Development"
     .FieldNames = True
     .RowNumbers = False
     .FillAdjacentFormulas = False
     .PreserveFormatting = True
     .RefreshOnFileOpen = False
     .BackgroundQuery = True
     .RefreshStyle = xlInsertDeleteCells
     .SavePassword = True
     .SaveData = True
     .AdjustColumnWidth = True
     .RefreshPeriod = 0
     .PreserveColumnInfo = True
     .Refresh BackgroundQuery:=False
     End With
     xlSheet.Range("A1").AutoFilter (1)
     xlApp.DisplayAlerts = False
    xlApp.Visible = True
    第一次执行没问题,退出EXCEL,按CTRL+ALT+DEL,仍可在关闭程序窗口看见EXCEL,知没有完全退出EXCEL,于是在另一按钮加入指令如下:
    xlApp.Quit
    Set xlApp = Nothing
    Set xlBook = Nothing
    Set xlSheet = Nothing
    执行后,按CTRL+ALT+DEL,仍可在关闭程序窗口看见EXCEL。此时第二次执行转EXCEL,出现错误信息:
    实时错误 ‘1004’
    对象'Range'的方法'_Global'失败。请问如何处理?
    水平: 刚入门

回答:

    把语句xlSheet.Range("A1").AutoFilter (1)去掉。在VB6.0,Win2000下通过。

此问题由qyh回答。

 
把这个问题推荐给朋友
   
   
您的意见类别
您的名字
您的电子邮件
您的建议(请尽可能详细)
 
 

版权所有 1997-2008 热情软件屋
如果您有任何建议和意见, 请给我发个电子邮件 askpro@china-askpro.com
Web Designed by ZebraStudio