【问题标题】:Convert date for file name [duplicate]转换文件名的日期[重复]
【发布时间】:2015-11-17 22:05:00
【问题描述】:

我无法将日期转换为可以将 Excel 文档另存为的格式。 IE。取出“/”和/或用“-”替换它们

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

我已经尝试替换我们,因为这似乎是显而易见的答案,但它什么也没做。一开始我以为是因为它不是字符串类型,但它仍然什么都不做。

然后我尝试通过将字符串作为数组迭代并手动替换来做到这一点,但什么也没做。

当前没有生成错误,并且 Wscript.Echo testArray(i) 正在输出 11/17/2015,这对我来说很奇怪,它完全在输出。

【问题讨论】:

标签: string excel date replace vbscript


【解决方案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

【讨论】:

  • 是的,做到了,我很尴尬。
猜你喜欢
  • 2015-07-05
  • 1970-01-01
  • 2023-04-08
  • 2018-02-24
  • 2011-05-23
  • 2014-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多