Search code examples
pythonexcelwin32comvba

How to change the date system in excel with code


I've got two excel spreadsheets I need to collate. One uses the 1900 base year system, the other uses 1904. I am filling the 1904 spreadsheet with data and then pulling in the 1900 sheet. I'd like to change the date system to be based on 1900 for the first sheet I fill up so that when I pull in the other sheet it doesn't screw up the dates.

I can't find the magic words to change this setting in excel programatically. I'll take it in any language, with any module (but I'm using win32com and python). I can figure it out from there.

Is it even possible?

Here are the instructions to do it manually:

http://answers.microsoft.com/en-us/office/forum/office_2007-excel/why-does-excel-2007-change-dates-when-i-copy-and/b0544a7f-bd82-4b5a-a843-e6ae22f2ef63


Solution

  • You may not have been aware that you can record a macro while you make changes in Excel Options. This is what I get.

    Sub Macro1()
        ActiveWorkbook.Date1904 = True
    End Sub
    

    Sometimes it is just easier to get the syntax and correct command through recording if it doesn't come off the top of your head.