I want to test the cells of an Excel sheet on Interior.Color. The VBA code works fine:
If cell.Interior.Color = RGB(255, 255, 204) Then
I have problems "translating" this code into VB.NET. I tried a lot of code but nothing works.
I have Option Explicit On
.
I have Option Strict On
.
This code in VB.NET gives no error but it does not work:
If cell.Interior.Color Is TryCast(RGB(255, 255, 204), Object) Then
Please note in VB.NET it seems to be If cell.Interior.Color Is
not If cell.Interior.Color =
Any suggestions? Thanks
I think I have to cast RGB(255, 255, 204) but I don't know how? Casting to Object gives no error but does not work.
Using most recent Visual Studio VB.NET and Add-in-express.
It does not work because the RGB object created with TryCast
and the object returned by excel are two different objects and objects are compared by reference not by their content.
Cast the the object returned by excel instead:
If DirectCast(cell.Interior.Color, Double) = RGB(255, 255, 204) Then
Finally I was able to make Interop work with my Office 365 Pro. The Color value returned by Excel is of type Double
, not Integer
as I expected first.