Dim xlApp     As Excel.Application
  Dim xlBook     As Excel.Workbook
  Dim sheet     As Worksheet
  '   Open   the   destination   Excel   workbook.
  Set xlApp = CreateObject("Excel.Application")
  Set xlBook = xlApp.Workbooks.Open("D:\Book1.xls")
  xlApp.Visible = True
  Set sheet = xlApp.Worksheets("Sheet1")
  
  Range("A3").Select
  ActiveCell.FormulaR1C1 = "购货方:" & Text1(0).Text
  Range("D3").Select
  ActiveCell.FormulaR1C1 = "供货方:" & Text1(10).Text
    
  xlApp.Visible = False
  '   Clean   up   everything.
  xlBook.SaveAs "c:\v.xls"
  xlBook.Close False
  xlApp.Quit
  Set xlBook = Nothing
  Set xlApp = Nothing这样处理,结果在进程里EXECL就关不掉了,求教

解决方案 »

  1.   

    以下是测试OK的Dim a     As ImageSize
    Set xlapp = CreateObject("Excel.Application") '创建EXCEL应用类
    xlapp.Visible = True '设置EXCEL可见
    Set xlbook = xlapp.Workbooks.Open("D:\vb\mode\test.xls") '打开EXCEL工作簿
    Dim xR     As Range
    Dim intFreeFile As Integer
    intFreeFile = FreeFileSql = "select * from product "
    Set xlsheet = xlbook.Worksheets(1) '打开EXCEL工作表
    xlsheet.Activate
    conn.Open ConnectString
    rs.Open Sql, conn, 1, 1
    i = 2
    Do While Not rs.EOF
    newsortid = rs("id")
    newsortname = rs("englishname")
    xlsheet.Cells(i, 1) = newsortname
    rs.MoveNext
    Loop
    rs.Close
    Set rs = Nothing
    conn.Close
    Set conn = Nothingxlapp.Worksheets.PrintPreview
    xlapp.DisplayAlerts = False
    xlsheet.SaveAs FileName:="d:\mode\xls\" & Date & ".xls"
    MsgBox "已成功导出到D盘mode文件夹内!", vbExclamation + vbOKOnly, "导出成功"
    xlapp.Quit
    Set xlapp = Nothing