我得到了一个无效的使用属性错误的行,我试图分配格式化的表名表。我假设这是一个语法问题。但是,我不知道我想做的是可能的,没有更多的代码或不同的代码。我想抓住表的表名,以便在下一行它可以添加到范围内创建格式化的表语法(即MyTable[EntityID])
Option Explicit
Private Sub Workbook_Open()
Dim ws As Worksheet
Dim wbkCurBook As Workbook
Dim searchValue As String
Dim searchSheet As String
Dim tableMatch As Range
Dim cell As Range
Dim combined As String
Dim x As Long
Dim LastColumn As Long
Dim tables As ListObject
Application.ScreenUpdating = False
Set wbkCurBook = ActiveWorkbook
'highlight all entityIDs with missing definitions
For x = 3 To Sheets.Count
Sheets(x).Activate
ws = ActiveSheet
tables = Sheets(x).ListObjects
For Each cell In Sheets(x).Range(tables & "[EntityID]")
searchValue = cell.Value
searchSheet = Sheets(x).Name
combined = searchSheet & " " & searchValue
With wbkCurBook.Sheets("Data Dictionary").Range("Dictionary[CombinedName]")
Set tableMatch = .Find(What:=combined, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If tableMatch Is Nothing Then
cell.Interior.Color = RGB(255, 0, 0)
End If
End With
Next cell
Next x
Application.ScreenUpdating = True
End Sub
2条答案
按热度按时间qmb5sa221#
因为你已经声明了
Dim tables As ListObject
,所以你必须使用SET,而且你还必须告诉你要使用哪个表。变更
到
然后像
tables.Name
一样使用它举个例子
vyswwuz22#
高亮显示缺失
Module1
,但是你可以将它复制到ThisWorkbook
模块中。然后,在你的Open
事件过程中(在ThisWorkbook module
中),只使用HighlightMissingDefinitions
行。可选