0
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

这是我用来在宏中打开 Excel 文件的代码,但它在第 8 行使用 Workbooks.Open() 函数报告了语法错误。我尝试过,但无法弄清楚我错在哪里。关于 Workbooks.Open() 函数的更多信息可以在这里找到:http: //msdn.microsoft.com/en-us/library/office/ff194819 (v=office.15).aspx

感谢您的关注!

4

2 回答 2

1

您不需要()in 方法调用(除非您正在分配结果)。利用

.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

尽管最好指定文件的完整路径。

于 2013-01-09T21:35:15.137 回答
0

.Workbooks.Open FileName:="test.xls", UpdateLinks:=0, ReadOnly:=False

于 2013-01-09T21:30:43.327 回答