防止VBA中的date格式?

我有一段代码,工作簿应该保存为文件path+前缀+用户input用户input框的任何date。 input的date格式应该是MMDDYYYY。 问题是VBA转换date并将其保存为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 

谢谢巴兰卡!

我想你可以使用format()函数来创build一个所需格式的string:

例:

 Dim strDate as String strDate = format(Date, "mmddyyyy") 

读:

  • MSDN: Format函数(VBA)