1

I'm having trouble getting a date into a format that will work to save an Excel document as. I.e. taking out the '/' and/or replacing them with "-"

Dim strDate
Dim intLen
Dim test
Dim testArray

strDate = Date

test = CStr(strDate)

testArray = Split(test)

intLen = Len(test)

For i =  0 To intLen
    if testArray(i) = "/" Then
        testArray(i) = "-"
    End If
Next

'Replace test, "/", "_"

For i =  0 To 3
    Wscript.Echo testArray(i)
Next


objExcel.ActiveWorkBook.SaveAs "C:\Inventory Script" & intLen & ".xls"
objExcel.Close
objExcel.Quit

I've tried to us replace as it seemed like the obvious answer, but it does nothing. At first I though it was because it was not a string type, but it still does nothing.

Then I tried to do it old school by iterating through the string as an array and manually replacing but that did nothing.

No errors are being generated currently and Wscript.Echo testArray(i) is outputting 11/17/2015 which is odd to me that it is outputting at all.

pnuts
  • 58,317
  • 11
  • 87
  • 139
wilk
  • 13
  • 2

1 Answers1

1
Dim strDate
Dim intLen
Dim test
Dim testArray

strDate = Date

test = CStr(strDate)

'''''' test= join(Split(test,"/"),"_")
'''''' test= join(Split(test,"-"),"_")
test= replace(test,"/","_")
test= replace(test,"-","_")

Wscript.echo test
milevyo
  • 2,165
  • 1
  • 13
  • 18