Public Sub text1(st As String)
Dim oXL As Object ' Excel application
Dim oBook As Object ' Excel workbook
Dim oSheet As Object ' Excel Worksheet
Dim i As Integer
'Start Excel and create a new workbook
Set oXL = CreateObject("Excel.application")
Set oBook = oXL.Workbooks.Open("E:\karan.xlsx")
Set ws = oBook.Sheets.Add
oBook.activesheet.Name = st
ws.Activate
答案 0 :(得分:0)
根据我的理解,您希望在调用函数时添加工作簿。在这种情况下,你可以使用它:
Sub AddWorkbook()
Sheets.Add After:=Sheets(Sheets.Count)
End Sub
如果您还想添加名称:
Private Sub AddWorkbookWithName(workbookName As String)
Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Select
Sheets(Sheets.Count).Name = workbookName
End Sub
Sub AddWorkbook()
AddWorkbookWithName ("MyWorkbookName")
End Sub