У меня есть такая таблица слов:
And I want to compare, using VBA, the column with the different columns from a excel table that looks like this:
введите описание изображения здесь
Я хочу сравнить столбец с другими столбцами и выделить красным в столбце слова, если одно значение не найдено (не имеет значения, что значения находятся в другом порядке в обеих таблицах ).
Я нашел несколько способов сравнить две таблицы в Excel с помощью vba, но я хотел бы посмотреть, можно ли сравнить одну таблицу в слове с другой в Excel, потому что я не могу это сделать . Большое спасибо!
Ps: Я хочу, чтобы макрос запускался из файла word, потому что я буду использовать кнопку, чтобы запустить его из слова.
Ps2: У меня есть этот код сейчас, но я получаю ошибку 450 в строке «With .Find», и я не знаю почему:
Private Sub CompararColumnas_Click()
Dim wrdTbl As Table
'Set your table
With ActiveDocument
If ActiveDocument.Tables.Count >= 1 Then
Set wrdTbl = .Tables(InputBox("Table # to copy? There are " & .Tables.Count & " tables to choose from."))
End If
End With
Dim AD_UsersPath As String
AD_UsersPath = "C:\Users\" & Environ("Username") & "\Desktop\Comparar Columnas VBA\Animales.xlsx"
Dim AD_USERS As Object
Set AD_USERS = CreateObject("Excel.Application")
AD_USERS.Visible = False
AD_USERS.Application.Workbooks.Open AD_UsersPath
LastRow = ThisDocument.Tables(1).Columns(1).Cells.Count
Dim I As Integer
For I = 1 To LastRow
wVal = ThisDocument.Tables(1).Cell(I, 1)
With AD_USERS.Range("A:A")
With .Find
.Forward = True
.Wrap = wdFindStop
.Execute FindText:=wVal, MatchCase:=True
End With
Do While .Find.Found
User = AD_USERS.Cells(.Row, 1).Text
.Find.Execute
Loop
End With
'User = AD_USERS.Cells(AD_USERS.Range("A:A").Find(what:="Perro").Row, 1).Text
'User = AD_USERS.Cells(AD_USERS.Range("A:A").Find(What:=wVal).Row, 1).Text
wrdTbl.Cell(I, 2).Range.Text = User
Next I
End Sub