我正在尝试编写代码,以将一个工作簿中的版本号与位于URL中的主电子表格中另一个工作簿中的版本列表进行对照。一切正常,并且指令相互竞争,但是我不断地“内存不足”提示任何想法为什么?
Option explicit
Sub test()
Dim MyPath as Object
Dim WorkbookType as Range
Dim Version as Integer
Dim CurrentVersion as Integer
Dim SearchRange as Object
Dim WorkbookVersion as Range
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Version = Worksheets(“sheet1”).Range(“Ver”)
Set WorkbookType = Worksheets(“sheet1”).Range(“Typ”)
Set MyPath Workbooks.open(Filename:=“https://LocationOfTheMasterSpreadsheet.xlsm”, ReadOnly:=True, UpdateLinks:=False)
Worksheets(“Master”).Activate
Set SearchRange = Worksheets(“Master”).Range(“Type”)
Set WorkbookType = SearchRange.Find(What:=WorkbookType, lookIn:=xlValues)
Set CurrentVersion = WorkbookType.Offset(0, 1)
If WorkbookType is nothing then
Msgbox “No such data found”
End If
If CurrentVersion = Version then
Msgbox “ success this is a current version”
ElseIf CurrentVersion <> Version then
Msgbox “Sorry you’re not using Current Version “
End If
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End sub
任何帮助将不胜感激。
谢谢
除非您打开的工作簿很大,否则我看不到任何会导致“内存不足”的信息。还有其他可能正在运行的代码吗?
Sub test()
Dim MyPath As Workbook
Dim WorkbookType As Range
Dim Version As Long
Dim CurrentVersion As Long
Dim SearchRange As Range
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'neither of these need to be Range types...
Version = ThisWorkbook.Worksheets("sheet1").Range("Ver").Value
WorkbookType = ThisWorkbook.Worksheets("sheet1").Range("Typ").Value
Set MyPath = Workbooks.Open(Filename:="https://LocationOfTheMasterSpreadsheet.xlsm", _
ReadOnly:=True, UpdateLinks:=False)
Set SearchRange = MyPath.Worksheets("Master").Range("Type")
Set WorkbookType = SearchRange.Find(What:=WorkbookType, _
LookIn:=xlValues, lookat:=xlWhole)
'test before trying to get CurrentVersion
If WorkbookType Is Nothing Then
MsgBox "No such data found"
Else
CurrentVersion = WorkbookType.Offset(0, 1).Value
If CurrentVersion = Version Then
MsgBox "Success this is a current version"
Else
MsgBox "Sorry you’re not using the Current Version (" _
& CurrentVersion & ")"
End If
End If
MyPath.Close False 'close without saving
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub