VB大神看看这一小段哪里有问题
PrivateSubCommand1_Click()Dimexcel_AppAsExcel.ApplicatiomDimexcel_BookAsExcel.Workboo...
Private Sub Command1_Click()
Dim excel_App As Excel.Applicatiom
Dim excel_Book As Excel.Workbook
Dim excel_sheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
Set excel_Book = excel_App.Workbooks.Open("C:\1.XLS")
Set excel_sheet = excel_Book.Worksheets("Sheet1")
excel_sheet.Range("C1").Value = 100
Set excel_sheet = Nothing
excel_App.ActiveWorkbook.Close savechanges:=True
Set excel_Book = Nothing
excel_App.Quit
Set excel_App = Nothing
End Sub
已经引用了 excel 15.0 library,结果运行显示用户定义类型未定义 展开
Dim excel_App As Excel.Applicatiom
Dim excel_Book As Excel.Workbook
Dim excel_sheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
Set excel_Book = excel_App.Workbooks.Open("C:\1.XLS")
Set excel_sheet = excel_Book.Worksheets("Sheet1")
excel_sheet.Range("C1").Value = 100
Set excel_sheet = Nothing
excel_App.ActiveWorkbook.Close savechanges:=True
Set excel_Book = Nothing
excel_App.Quit
Set excel_App = Nothing
End Sub
已经引用了 excel 15.0 library,结果运行显示用户定义类型未定义 展开
2个回答
展开全部
Private Sub Command1_Click()
Dim excel_App As Excel.Application
Dim excel_Book As Excel.Workbook
Dim excel_sheet As Excel.Worksheet
Set excel_App = CreateObject("Excel.Application")
excel_App.Visible = False
Set excel_Book = excel_App.Workbooks.Open("C:\1.XLSx")
Set excel_sheet = excel_Book.Worksheets("Sheet1")
excel_sheet.Range("C1").Value = 100
Set excel_sheet = Nothing
excel_App.ActiveWorkbook.Close savechanges:=True
Set excel_Book = Nothing
excel_App.Quit
Set excel_App = Nothing
End Sub
经过验证,一般说来需要先引用,后写代码,这段代码在我这运行通过,那个设置属性的 语句不知道为什么运行不能通过,让我给去掉了,然后运行完全通过。只是我这用的是exel2007那个文件的扩展名改了。别的都没什么了。不行再追
更多追问追答
追答
你上边那个代码还是不对 就是这行上边,那行还有再上边那行 应该改成
Set excel_App = CreateObject("Excel.Application")
excel_App.Visible = False
就没问题了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询