- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
We have a project management script that takes the current date and then writes this to an excel document. Now most of the time this works okay, but at the beginning of each month the dates get switched from EU style to US style (dd/MM/yyyy -> MM/dd/yyyy)
I already put in a small message box to verify if the date string is correct, and for as far as I can tell Inventor and iLogic are doing okay (the string follows the dd/MM/yyyy notation).
However, when I open the excel pretty much all dates up to 12/.../2024 are messed up to MM/dd/yyyy.
Next guess was that Excel is dropping the ball, but when I change the cell type it actually gives me the wrong full date.
Example, a project from the 9th of December 2024 -> iLogic gets the current date as a string -> message box shows "9/12/2024", I open the Excel file and it shows "12/09/2024" in the cell and when I change it to a long notation it becomes "12 September 2024".
Does anyone know where the translation between the string in Inventor and the content of the cell in Excel goes wrong?
Snippet of code regarding the date function:
' Get the current date and start time
Dim currentDate As String = Now.ToString("dd/MM/yyyy")
MessageBox.Show(currentDate, "currentDate")
....
' Main code to write data to Excel
Dim excelApp As Object
Dim excelWorkbook As Object
Dim excelSheet As Object
' Open Excel application and workbook
excelApp.Visible = False ' Excel stays in the background
excelWorkbook = excelApp.Workbooks.Open(filePath)
excelSheet = excelWorkbook.Sheets(1)
' Find the last used row in the sheet
Dim lastRow As Integer
lastRow = excelSheet.Cells(excelSheet.Rows.Count, 1).End(-4162).Row + 1 ' -4162 is xlUp
' Write data to Excel in the specified order
excelSheet.Cells(lastRow, 1).Value = currentDate ' Date
' Save and close Excel
excelWorkbook.Save()
excelWorkbook.Close()
excelApp.Quit()
This results in this:
I have already though about adding a " ' " in front of the string so that Excel is forced to use it as plain text, but I'd like to use these date for analyzing purposes, so I'd rather keep them in a date format.
Solved! Go to Solution.