我正在尝试将刚创建的仪表板设置为在将来进行更改时自动进行更新(嗯,一旦它再次打开)。我已经制定了以下方法,但是在标有**的行上始终出现“类型不匹配”错误。我觉得我在这里似乎遗漏了一些明显的东西,但是对于我的一生,我无法弄清楚。有什么想法吗?
Private Sub Workbook_Open()
Dim UpDateBook As Workbook
Dim CurrVer As String
Dim AdminFile As String
Dim AdminFolder As String
Dim MyPath As String
''Change the next two according to where the admin file will be located.
AdminFile = "\\dallfile\Databases\Reports\Dashboard\Dashboard Update.xlsx"
AdminFolder = "\\dallfile\Databases\Reports\Dashboard"
MyPath = ThisWorkbook.Path
MyPath = MyPath & "\"
Application.ScreenUpdating = False
Set UpDateBook = Workbooks.Open(AdminFile, , True)
**CurrVer = Workbooks(UpDateBook).Sheets("Version_Log").Range("A5000").End(xlUp).Value
CurrVer = CurrVer & ".xlsm"
If ThisWorkbook.Name <> CurrVer Then
MsgBox ("There is a new update for your file available. It will be loaded as soon as you press OK")
Workbooks.Open Filename:=AdminFolder & CurrVer
Application.EnableEvents = False
Workbooks(CurrVer).SaveAs Filename:=MyPath & CurrVer, FileFormat:=xlNormal
Application.EnableEvents = True
With ThisWorkbook
.Saved = True
.ChangeFileAccess Mode:=xlReadOnly
Kill pathname:=.FullName
.Close savechanges:=False
End With
End If
Application.ScreenUpdating = True
End Sub
最佳答案
我认为这是因为您使用的工作簿对象不正确。
您在这里设置工作簿。
Set UpDateBook = Workbooks.Open(AdminFile, , True)
然后应该像这样使用它。
CurrVer = UpDateBook.Sheets("Version_Log").Range("A5000").End(xlUp).Value
关于excel - 从工作簿中提取.value时类型不匹配,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20009318/