Welcome to Golden Software Support

Julian numbers to Gregorian dates


1 comment

  • Avatar
    Kari Dickenson


    There is not a way to reformat the name of a file in Scripter. However, you could copy the file name to a cell in the worksheet, reformat the data in the worksheet to show the date in date format, and then save the worksheet using the reformatted cell contents as the file name. This would work in theory, but when I tried it, the script was trying to put quotes around the date, and you can't save a filename with quotes. You might know of a way to remove the quotes from the filename. The script is below if you want to try and work with it. If this worked as expected, all you would need to do is specify at the beginning the script an empty cell location and the date format you wish. The date format options you can choose from are listed in the Help (http://surferhelp.goldensoftware.com/#t=autoobjects%2Flink_wkscellformat.htm - but note they need "wks" preceding each enumeration - I will have our documentation personnel update this). That's the only idea I have to reformat the name of the data files.



    Sub Main

    Dim SurferApp As Object
    Set SurferApp = CreateObject("Surfer.Application")
    SurferApp.Visible = True

    '========USER VARIABLES=============
    EmptyCell$ = "D1"
    DateFormat = wksDATEFMT_D_MON_YY 'ex: 7-Sep-98

    Dim Wks As Object

    file1$ = GetFilePath(,"csv")

    If file1$ <> "" Then
    Set Wks = SurferApp.Documents.Open(file1$)
    End If

    filename$ = Left(file1,Len(file1$)-4) 'filename minus extension
    filename2$=Mid(filename$,(InStrRev(filename,"\")+1)) 'filename minus filepath

    Wks.Cells(EmptyCell$).Value = filename2$
    Wks.Cells(EmptyCell$).Format.NumericType = wksTypeDateTime
    Wks.Cells(EmptyCell$).Format.DateFmtType = DateFormat

    NewName$= Wks.Cells(EmptyCell$).Value

    filepath =Left(filename$,(InStrRev(filename$,"\")))

    Wks.SaveAs (filepath+NewName$+".csv")

    End Sub
    Comment actions Permalink

Please sign in to leave a comment.