我有一段代码,其中工作簿应保存为文件路径+前缀+用户输入用户输入框的日期。输入日期应为MMDDYYYY格式。问题是VBA转换日期并将其保存为MM-DD-YYYY格式。我该如何防止这种情况。
我的代码:
With prevdaily
Application.DisplayAlerts = False
' Check for year folder and create if needed
If Len(Dir("G:\AccPac ERP Daily Reports\" & Year(Date), vbDirectory)) = 0 Then
MkDir "G:\AccPac ERP Daily Reports\" & Year(Date)
End If
' Check for month folder and create if needed
If Len(Dir("G:\AccPac ERP Daily Reports\" & Year(Date) & "\" & Format(Date, "mm ") & MonthName(Month(Date), False), vbDirectory)) = 0 Then
MkDir "G:\AccPac ERP Daily Reports\" & Year(Date) & "\" & Format(Date, "mm ") & MonthName(Month(Date), False)
End If
fname2 = InputBox("Please enter date of Daily Income Journal to save")
fname2 = fname2 & ".xlsx"
fpath = "G:\AccPac ERP Daily Reports\" & Year(Date) & "\" & Format(Date, "mm ") & MonthName(Month(Date), False) & "\"
ActiveWorkbook.SaveAs FileName:=fpath & "Daily Income Journal-" & fname
谢谢巴兰卡!
答案 0 :(得分:2)
我认为您可以使用format()
函数创建所需格式的字符串:
示例:
Dim strDate as String
strDate = format(Date, "mmddyyyy")
读: