I'm having a problem when comparing dates:
Sub Main()
Dim xlApp, xlApp1, xlApp2 As Excel.Application
Dim xlWorkBook, xlWorkBook1, xlWorkBook2 As Excel.Workbook
Dim xlWorkSheet, xlWorkSheet1, xlWorkSheet2 As Excel.Worksheet
Dim folder, m, n As String
Dim subfolders As String()
Dim i, j, c, k, l, lastrow As Integer
Dim fec,temp As Date
Dim nulls As Boolean
nulos = False
folder = My.Application.Info.DirectoryPath
ChDir(CurDir())
subfolders = IO.Directory.GetDirectories(CurDir())
xlApp = New Excel.ApplicationClass
xlApp2 = New Excel.ApplicationClass
xlApp1 = New Excel.ApplicationClass
Try
xlWorkBook = xlApp.Workbooks.Open("d:\File where data will be copied.xlsx")
xlWorkSheet = xlWorkBook.Worksheets("SheetName")
xlWorkSheet.Activate()
xlWorkBook2 = xlApp2.Workbooks.Open("d:\File Where Dates Are Recorded.xlsx")
xlWorkSheet2 = xlWorkBook2.Worksheets("SheetName")
xlWorkSheet2.Activate()
i = 2
For Each f1 In subfolders
ChDir(f1)
m = Dir("*.xlsx")
Do While m <> ""
If Strings.Left(m, 6) = "DOC_ID" Then
j = 2
Do While xlWorkSheet2.Cells(j, 1).Value <> ""
If xlWorkSheet2.Cells(j, 1).Value = m Then
fec = xlWorkSheet2.Cells(j, 2).value
'Check if last write date is the same as the one recorded in the file
temp = File.GetLastWriteTime(CurDir() & "\" & m)
If fec <> File.GetLastWriteTime(CurDir() & "\" & m) Then
.
.
.
In the last line
If fec <> File.GetLastWriteTime(CurDir() & "\" & m)
I'm comparing the modified date of a file with a date stored inside a worksheet cell as date format. When debugging, fec and temp have the same value(already tested in debugger) but It still enters inside the if condition...Why? Any ideas?
Values in locals window:
fec #11/15/2013 6:06:01 PM#
temp #11/15/2013 6:06:01 PM#