Oh, my bad, I missed that you also had a problem with:
Code:
If .Item(i).Value = Date.Now Then
Hmm... That looks fine to me. It could be a Coercion issue though, I guess. I would try:
Code:
If CDate(.Item(i).Value) = Date.Now Then
You should also strongly consider using Option Strict On. This will force you to use CType() at a number of locations which will help straighten out these Casting and Coercion issues at Compile Time instead of failing at Run Time.
The good news is that the IDE will tell you
exactly which lines need a CType() added, so you really dont really have to worry about it. For example, within your code I am certain that the IDE/Compiler will tell you that the following line:
Code:
With WB.Worksheets("Sheet1")
will need a CType() added. What you need to do in this case is force the Cast to a Worksheet object by changing the above line to:
Code:
With CType(WB.Worksheets("Sheet1"), Excel.Worksheet)
I know that this looks positively silly, for the Worksheet Collection should return only a Worksheet object anyway, but unfortunately this is not 100% true. The Worksheets collection is actually polymorphic and can return an Excel 4.0 Macro sheet. So, technically, the compiler does not know which object type you are referring to at Compile time. Using CType() tells it. And using Option Strict On at the top of your Module enforces that CType() will be required any time there is an ambiguity.
I do not know for sure if Option Strict On would flag down your line:
Code:
If .Item(i).Value = Date.Now Then
but I suspect that it would. The more of these things that you can track down at Compile Time instead of at Run Time, the better...
-- Mike