nscotty_2000
New member
- Local time
- Tomorrow, 04:24
- Joined
- Oct 11, 2010
- Messages
- 7
Hi, I have been searching through forums and cannot find an answer to my problem. I have all time/date settings on the machine set to dd/mm/yyyy.
I have "Short Date" as the format for all date fields in Access and have also set the MS Office default settings to dd/mm/yyyy. However when creating an excel file with the below code it reverts the date in cells back to mm/dd/yyyy. This is doing my head in so any help would be much appreciated. Thanks in advance.
Sub ExportFilesForImport()
Dim CurrentDate, CurrentFileName, Path
Dim xlObj As Object, xlFile, iCol, iRow
CurrentDate = Format(Now(), "yyyymdd-hhmmss")
CurrentFileName = "ePick Export File - " & CurrentDate & ".XLS"
Path = "C:\Independent Order Console\ePick Import Files\"
DoCmd.OutputTo acOutputQuery, "Sheet1", acFormatXLS, Path & CurrentFileName, False
xlFile = Path & CurrentFileName
Set xlObj = CreateObject("excel.application")
xlObj.Workbooks.Open xlFile
With xlObj
For iRow = 1 To .Sheets(1).usedrange.rows.Count
For iCol = 1 To .Sheets(1).usedrange.Columns.Count
.cells(iRow, iCol).Value = Replace(Replace(.cells(iRow, iCol), "DelivDate", "Deliv.Date"), "DelivDate", "Deliv.Date")
Next
Next
.activeworkbook.Save
End With
xlObj.Quit
Set xlObj = Nothing
End Sub
I have "Short Date" as the format for all date fields in Access and have also set the MS Office default settings to dd/mm/yyyy. However when creating an excel file with the below code it reverts the date in cells back to mm/dd/yyyy. This is doing my head in so any help would be much appreciated. Thanks in advance.
Sub ExportFilesForImport()
Dim CurrentDate, CurrentFileName, Path
Dim xlObj As Object, xlFile, iCol, iRow
CurrentDate = Format(Now(), "yyyymdd-hhmmss")
CurrentFileName = "ePick Export File - " & CurrentDate & ".XLS"
Path = "C:\Independent Order Console\ePick Import Files\"
DoCmd.OutputTo acOutputQuery, "Sheet1", acFormatXLS, Path & CurrentFileName, False
xlFile = Path & CurrentFileName
Set xlObj = CreateObject("excel.application")
xlObj.Workbooks.Open xlFile
With xlObj
For iRow = 1 To .Sheets(1).usedrange.rows.Count
For iCol = 1 To .Sheets(1).usedrange.Columns.Count
.cells(iRow, iCol).Value = Replace(Replace(.cells(iRow, iCol), "DelivDate", "Deliv.Date"), "DelivDate", "Deliv.Date")
Next
Next
.activeworkbook.Save
End With
xlObj.Quit
Set xlObj = Nothing
End Sub