我有两个工作簿,在工作簿1中我有一个宏,它根据项目的整体状态更新一个单元格的内部颜色。
工作簿2旨在作为所有项目的摘要,我需要它来反映工作簿1中该单元格的颜色。
我对VBA还是比较新的......我怎么会这样做呢?
谢谢!
答案 0 :(得分:0)
Sub copyColorOfCell()
Dim workbook1, workbook2 As Workbook
Set workbook1 = Workbooks("workbookName1.xlsx")
Set workbook2 = Workbooks("workbookName2.xlsx")
Dim worksheet1, worksheet2 As Worksheet
Set worksheet1 = workbook1.Sheets("worksheetName")
Set worksheet2 = workbook2.Sheets("worksheetName")
Dim cell1, cell2 As Range
Set cell1 = worksheet1.Range("A1")
Set cell2 = worksheet2.Range("A1")
cell2.Interior.Color = cell1.Interior.Color
End Sub
替换工作簿和工作表名称(您也可以使用索引)并指定所需的单元格。