我有一個工作表中引用其他工作表在同一工作簿「產品列表」另一個工作表。 VBA應該將工作表保存爲獨立的電子表格,並且如果任何公式包含對我的產品列表的引用,也應該將其保存。複製如果主引用它的公式時,Excel VBA
我嘗試使用以下命令:
Function UsesProductsList(ws As Worksheet) As Boolean
Dim r As Range
Dim c As Range
Set r = ws.UsedRange
UsesProductsList = False
For Each c In r
If InStr(1, c.Formula, ProductsList.Name) > 0 Then
UsesProductsList = True
Exit Function
End If
Next c
End Function
,但有一個錯誤。當我調試錯誤,我可以看到它有事情做與下面的行If InStr(1, c.Formula, ProductsList.Name) > 0 Then
,當我徘徊在鼠標我可以看到,我在小區A1
公式。
你有什麼錯誤? – dee
運行時錯誤424對象要求 – AlexB
'''ProductsList.Name'''可能是原因。如果「產品列表」工作簿的名稱,則使用'''Workbooks'''收集這樣的:'''工作簿(「產品列表」)工作表(1).Name''' ......或任何名稱。工作簿(「ProductsList」)。工作表(「SomeSheetName」)。Name''' – dee