内部颜色给vba错误?
我得到一个运行时错误,1004当我在vba中运行下面的代码
MsgBox Workbooks(SourceFile1).Worksheets(WS).Range(Cells(ThisRow, ThisColumn), Cells(ThisRow, ThisColumn)).Interior.Color
但是在下面的代码中不会出现任何错误:
MsgBox Workbooks(DestinationFile).Sheets(1).Range(Cells(I, 14), Cells(I, 14)).Interior.Color
SourceFile1打开,因为我编码这样做。 此外,ThisRow显示值为9,并且在debugging模式下,ThisColumn显示为11
有针对这个的解决方法吗?
谢谢
假设你的variables是合适的,你的单元格调用没有适当的工作表限定 – 你需要:
With Workbooks(SourceFile1).Worksheets(WS) MsgBox .Range(.Cells(ThisRow, ThisColumn), .Cells(ThisRow, ThisColumn)).Interior.Color End With
或者在这种情况下,因为您只查看一个单元:
Msgbox Workbooks(SourceFile1).Worksheets(WS).Cells(ThisRow, ThisColumn).Interior.Color