brian_choi
Oct 12th, 2005, 10:09 PM
Dear Expert
I want to output the recordset to Excel and set the date format in Excel dd-mm-yyyy. However, when I use below syntax, the outout of format is different under different case
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add
With oSheet
For i = 0 To objRs.Fields.Count - 1
oSheet.Cells(1, i + 1).Value = Trim(CStr(objRs.Fields(i).Name))
objRs.MoveFirst
.Range("F1:F" & objRs.RecordCount + 1).NumberFormat = "dd-mm-yyyy"
.Range("G1:G" & objRs.RecordCount + 1).NumberFormat = "dd-mm-yyyy"
For j = 1 To objRs.RecordCount
If i = 5 Or i = 6 Then
oSheet.Cells(j + 1, i + 1).NumberFormat = "dd-mm-yyyy"
End If
oSheet.Cells(j + 1, i + 1).Value = objRs.Fields(i).Value
objRs.MoveNext
Next
Next
End With
?objRs.Fields(i).Value
23-09-2005
02-09-2005
?oSheet.Cells(j + 1, i + 1).Value
23-09-2005
09-02-2005
Even the date output in recordset is 02-09-2005, and the setting of the ouput of Excel is dd-mm-yyyy. The final output of Excel is still 09-02-2005.
My PC regional setting is in dd-mm-yyyy.
Any suggestion
Thank you very much
Brian choi
I want to output the recordset to Excel and set the date format in Excel dd-mm-yyyy. However, when I use below syntax, the outout of format is different under different case
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add
With oSheet
For i = 0 To objRs.Fields.Count - 1
oSheet.Cells(1, i + 1).Value = Trim(CStr(objRs.Fields(i).Name))
objRs.MoveFirst
.Range("F1:F" & objRs.RecordCount + 1).NumberFormat = "dd-mm-yyyy"
.Range("G1:G" & objRs.RecordCount + 1).NumberFormat = "dd-mm-yyyy"
For j = 1 To objRs.RecordCount
If i = 5 Or i = 6 Then
oSheet.Cells(j + 1, i + 1).NumberFormat = "dd-mm-yyyy"
End If
oSheet.Cells(j + 1, i + 1).Value = objRs.Fields(i).Value
objRs.MoveNext
Next
Next
End With
?objRs.Fields(i).Value
23-09-2005
02-09-2005
?oSheet.Cells(j + 1, i + 1).Value
23-09-2005
09-02-2005
Even the date output in recordset is 02-09-2005, and the setting of the ouput of Excel is dd-mm-yyyy. The final output of Excel is still 09-02-2005.
My PC regional setting is in dd-mm-yyyy.
Any suggestion
Thank you very much
Brian choi