我用Commondialog控件显示"另存为"对话框,输入文件名后后按"保存",并没有新建一个excell表,我要怎么新建一个excell表.

解决方案 »

  1.   

    Dim ExcelApp As Excel.Application
    Dim ExcelBook As Excel.Workbook
    Dim ExcelSheet As Excel.Worksheet
    Set ExcelApp = CreateObject("excel.application") '创建EXCEL句柄
    ExcelApp.Visible = False '
    Set ExcelBook = ExcelApp.Workbooks.Add '创建EXCEL工作薄
    Set ExcelSheet = ExcelBook.Worksheets(1) '创建EXCEL工作表
    ExcelSheet.Cells(1, 1).Value = "编号"
    ExcelSheet.Cells(1, 2).Value = "单位名称"
    ExcelSheet.Cells(1, 3).Value = "负责人"
    ExcelSheet.Cells(1, 4).Value = "单位地址"
    ExcelSheet.Cells(1, 5).Value = "类别"
    ExcelSheet.Cells(1, 6).Value = "许可项目"
    ExcelSheet.Cells(1, 7).Value = "区域"
    ExcelSheet.Cells(1, 8).Value = "乡镇"
    ExcelSheet.Cells(1, 9).Value = "发证日期"
    ExcelSheet.Cells(1, 10).Value = "截止日期"
    ExcelSheet.Range("A2").CopyFromRecordset rsExcelBook.SaveAs strExcelPath + "临时卫生许可证报表"
    ExcelApp.Visible = True
    这些代码看一下,就会了。
      

  2.   

    谢谢,我基本懂了,可是我发现如果:Set ExcelSheet = ExcelBook.Worksheets(4) 
    它就会说超出范围,我该怎么访问>3的工作表呢?