我有一段代码,其中工作簿应保存为文件路径+前缀+用户在用户输入框中输入的任何日期。输入的日期应采用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
谢谢Barranka!
我认为您可以使用该format()
函数创建具有所需格式的字符串:
例子:
Dim strDate as String
strDate = format(Date, "mmddyyyy")
读:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句