VB怎么样新建EXCEL工作薄?
发布网友
发布时间:2022-04-22 22:15
我来回答
共2个回答
热心网友
时间:2023-10-05 10:56
Set xlsApp = CreateObject("Excel.Application")
Set xlBook = xlsApp.Workbooks.Add
Set xlsheet = xlBook.Worksheets.add
xlSheet.Cells(1, 1) = 1111 '给单元格(row,col)赋值
a = xlSheet.Cells(1, 1)
xlBook.SaveAs "E:\工作薄.xls"
xlsapp.quit追问
这里如果点击 否 或者 取消 就会报错
追答加上一句错误处理语句:
Dim xlsApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlsApp = CreateObject("Excel.Application")
Set xlBook = xlsApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Cells(1, 1) = 1111 '给单元格(row,col)赋值
a = xlSheet.Cells(1, 1)
On Error Resume Next
xlBook.SaveAs "E:\工作薄.xls"
xlsApp.Quit
热心网友
时间:2023-10-05 10:57
Dim XlApp As New Excel.Application
Dim XLWorkBook As New Excel.Workbook
Dim XLWorkSheet As New Excel.Worksheet
Set XLWorkBook = XlApp.Workbooks.Add
Set XLWorkSheet = XLWorkBook.Worksheets(1)
XlApp.Visible = True