文件名发生了变化,所以我使用通配符*在Workbooks.Open语句中引用它
最后一行代码抛出类型不匹配错误,如何更改语法以修复代码?
Dim JohnnyFootball As Workbook
Workbooks.Open Filename:= _
"T:\ConA\RIP\Extracts\Reference" & "*.xlsx"
Sheets("Sheet1").Select
Set JohnnyFootball = ActiveWorkbook
'Other [redacted] code here runs fine
'Code below throws type mismatch error
Workbooks(JohnnyFootball).Close SaveChanges:=False
答案 0 :(得分:2)
最后一行应如下所示:
JohnnyFootball.Close SaveChanges:=False
JohnnyFootball
是Workbook
变量。要从Workbooks
集合中获取元素,您必须传递它的名称或索引。