且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用VB6将工作表添加到Excel文件

更新时间:2023-11-27 09:46:10

您需要以与创建工作簿相同的方式来创建工作表对象.

You need to create the worksheet object in the same manner that you created the workbook.

Dim ExcelApp As Excel.Application
Dim ExcelWorkbook As Excel.Workbook
Dim ExcelSheet As Excel.Worksheet

    Set ExcelApp = Excel.Application
    Set ExcelWorkbook = ExcelApp.Workbooks.Add
    Set ExcelSheet = ExcelWorkbook.Worksheets.Add


    ExcelSheet.Name = "New_Sheet_Name " & CStr(Unique_ID)



Unique_ID:每个工作表都需要使用唯一的名称进行标识.

还请确保您处置对象,否则在程序关闭后Excel应用程序将继续运行.



Unique_ID: each sheet needs to be identified with a unique name.

Also assure that you dispose the objects or the Excel application will keep running after your program closes.

Set ExcelSheet = Nothing
Set ExcelWorkbook = Nothing
Set ExcelApp = Nothing