Sub test()
Dim objXL
Set objXL = CreateObject("Excel.Application")
Dim FileName As Variant
Dim UpdateLinks As Variant
Dim ReadOnly As Variant
With objXL
.Workbooks.Open(FileName:= "test.xls",UpdateLinks:=0,ReadOnly:=False)
.Visible = True
End With
Set objXL = Nothing
End Sub
以下是我用于在Macro中打开Excel文件的代码,但它在Workbooks.Open()函数的第8行报告了语法错误。我试过但无法弄清楚我哪里出错了。有关Workbooks.Open()函数的更多信息,请访问:http://msdn.microsoft.com/en-us/library/office/ff194819(v=office.15).aspx
感谢您的关注!
答案 0 :(得分:1)
在方法调用中不需要()
(除非您要分配结果)。使用
.Workbooks.Open(FileName:= "test.xls",UpdateLinks:=0,ReadOnly:=False)
那就是说,你为什么要创建一个应用程序对象?如果在 Excel 中编码,则可以使用
Dim wb As Workbook
Set wb = Workbooks.Open(FileName:="test.xls", UpdateLinks:=0, ReadOnly:=False)
或只是
Workbooks.Open FileName:="test.xls", UpdateLinks:=0, ReadOnly:=False
虽然最好指定文件的完整路径。
答案 1 :(得分:0)
.Workbooks.Open FileName:="test.xls", UpdateLinks:=0, ReadOnly:=False