此代码完全适用于本地工作簿,但我无法弄清楚如何(我在S.O.F.上尝试了一些建议)让它在Personal.xlsb文件中工作。非常感谢任何帮助 '这个宏在本地工作 - 需要让它在Personal.xlsb级别工作
'This macro works locally - need to get it to work at the Personal.xlsb level
Sub AdvLookupVals()
Dim colA_Range As Range
Dim rngLookupRange As Range
Dim rngFoundRange As Range
Dim wb As Workbook
ThisWorkbook.Worksheets("Sheet1").Activate
'when you do this, Lookup.xls becomes active and sets the range
Set wb = Workbooks.Open("C:\Lists\Resource_Lookup.xlsx", True, True) ' open the source workbook, read only
Set rngLookupRange = wb.Worksheets("Sheet1").Range("A1:A656")
'Makes target workbook active again
ThisWorkbook.Activate
'Set rngFoundRange = wb.Worksheets("Sheet1").Range("A1:A653")
'rngFoundRange.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= '_ 'hoping this would make the macro work in Personal.xlsb
Range("A1:A653").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
rngLookupRange, Unique:=False 'rngLookupRange gets the criteria from above. .filters by name.
'releases resources back to the system and close the other workbook
Set rngLookupRange = Nothing
wb.Close False ' close the source workbook without saving any changes
Set wb = Nothing ' frees memory
End Sub