Excel 在VBA中防止日期格式化?

Excel 在VBA中防止日期格式化?,excel,vba,Excel,Vba,我有一段代码,其中工作簿应保存为文件路径+前缀+用户在“用户取消打印”框中输入的任何日期。输入的日期格式应为MMDDYYYY。问题是VBA转换日期并将其保存为MM-DD-YYYY格式。我如何防止这种情况 我的代码: With prevdaily Application.DisplayAlerts = False ' Check for year folder and create if needed If Len(Dir("

我有一段代码,其中工作簿应保存为文件路径+前缀+用户在“用户取消打印”框中输入的任何日期。输入的日期格式应为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

谢谢你,巴兰卡

我认为您可以使用
format()
函数创建具有所需格式的字符串:

例如:

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