【发布时间】:2020-09-17 11:39:28
【问题描述】:
我尝试比较我在 excel 中使用两个不同按钮放置的两个工作簿,然后使用第三个按钮比较并将第二个工作簿中的所有差异涂成红色。我很新,但我的工作需要它,我目前已完成将两个具有相似代码的文件添加到两个按钮中:
Sub openDialogTemplate()
Dim ofd As Office.FileDialog
Dim temwb As Workbook
Set ofd = Application.FileDialog(msoFileDialogFilePicker)
With ofd
.AllowMultiSelect = False
.Title = "Please select the Template file."
.Filters.Clear
.Filters.Add "Excel 2003", "*.xlsx"
.Filters.Add "All Files", "*.*"
If .Show = True Then
textFileName = .SelectedItems(1)
End If
Workbooks.Open Filename:=textFileName
Set temwb = ActiveWorkbook
End With
End Sub
和
Sub openDialogMaster()
Dim fd As Office.FileDialog
Dim maswb As Workbook
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
.Title = "Please select the Master file."
.Filters.Clear
.Filters.Add "Excel 2003", "*.xlsx"
.Filters.Add "All Files", "*.*"
If .Show = True Then
txtFileName = .SelectedItems(1)
End If
Workbooks.Open Filename:=txtFileName
Set maswb = ActiveWorkbook
End With
End Sub
我不知道如何使用 temwb 和 maswb 中的工作簿正确编写循环,以逐个单元格地进行,并将第二个工作簿中的每个不同单元格涂成红色。
【问题讨论】:
-
我假设您的第二个工作簿(您要在其中混合单元格的那个)是 Master 工作簿?另外,两个工作簿是否会有相同的数据集?你能提供你的 2 张纸的样本吗?