0
Hello. I’m having trouble transferring some dates like Baseline Start, Baseline Finish, Actual Start, Actual Msproject Finish to a spreadsheet in excel. Here is the code snippet.
Dim xlSheet As Excel.Worksheet
Dim wb As Workbook
Dim Prog As MSProject.Project
Dim Proj As MSProject.Application
Dim t As Task
Dim i As Long
[...]
For Each t In Prog.Tasks
i = i + 1
Set xlSheet = wb.Worksheets(6)
xlSheet.Cells(i, 1).Value = Proj.GetCellInfo(7, i).Task.Name
xlSheet.Cells(i, 2).Value = Mid((Proj.GetCellInfo(10, i).Task.BaselineStart), 1, 11)
xlSheet.Cells(i, 3).Value = Mid((Proj.GetCellInfo(11, i).Task.BaselineFinish), 1 , 11)
xlSheet.Cells(i, 4).Value = Mid((Proj.GetCellInfo(12, i).Task.ActualStart), 1 , 11)
xlSheet.Cells(i, 5).Value = Mid((Proj.GetCellInfo(13, i).Task.ActualFinish), 1 , 11)
xlSheet.Cells(i, 6).Value = Proj.GetCellInfo(14, i).Task.ResourceNames
Next t
When I use the mid substring, it is to remove the schedules that come along with the date. But when this date is passed to the spreadsheet in excel, it comes in mm/dd/yyyy format. If I don’t use substring, the date comes in dd/mm/yyyy format but with the hours.
When I don’t use a substring, the date is passed so 05/12/2016 08:00:00
When I use the Mid function, the value is like this.
However, the date is passed to the spreadsheet with the following value.
What could be causing this inversion in format?
Whether Excel automatically converts the date to
"mm/dd/yyyy"
, probably your system is configured in English, which would justify the change. Try puttingxlSheet.Cells(i,2).NumberFormat = "dd/mm/yyyy"
after the data have been copied.– Luiz Vieira
Luiz, you are right, my system is in English. But your solution worked when I put the format "mm/dd/yyyy". The reason I do not know.
– user67626
The reason is this: the configuration of the system in English (American) awaits the date with the month before the day. If it worked as you said, probably the system is in English and Excel in Portuguese. But anyway, if it worked, it’s worth it. I will post as an answer to help other people in the future. So, if you really think the answer helped you, please consider mark her as accepted, okay?
– Luiz Vieira