列出工作簿中的所有VLookups

我有一个很大的Excel文件有很多不同的工作表,每个包含很多的vlookups。

我想将这个文件和一些文件链接到一个新的文件夹。

我改变了macros中的path,但是有没有办法在所有有外部链接的工作表中find所有的vlookup? 我的意思是指向这些文件的一个链接,我也将移动(因此我应该改变他们的path)。

如果有一种方法可以列出文件中存在的所有Vlookups和它们所在单元格中的单元格,那就太好了。

下面的函数将收集具有公式的单元格,并返回一个Range对象。

function FindFormulaInSheet(ws As Worksheet, functionName As String) as Range Dim formulas As Range Dim c As Range For Each c In ws.UsedRange.SpecialCells(xlCellTypeFormulas) If InStr(c.Formula, "VLOOKUP") > 0 Then If formulas Is Nothing Then Set formulas = c Else Set formulas = Union(formulas, c) End If End If Next c set FindFormulaInSheet = formulas End function 

所以,在你的情况下,例如(将所有VLOOKUP标记为黄色):

 dim r as Range set r = FindFormulaInSheet (activeSheet, "VLOOKUP") r.interior.Color = vbYellow 

当然,你可以做任何你想要的范围,而不是标记为黄色。