重新格式化存储为整数的输入框值,以便在save中使用



我试图使用两个单独的输入框返回值在我的文件名中使用,文件名的格式必须非常具体,因为它是一个上传文件。

我需要年份和月份在文件名中,但是月份在文件名中出现了两次,在一个实例中,它在文件名中以MM或06的形式出现,在另一个实例中,它在文件名中以M或6的形式出现。

我有代码返回我输入的年和月,目前是2022和6。
文件名中的第二个月的格式正确为6,但我需要文件名中的第一个月的格式为06,我知道这是NumberFormat "0#"但是我不知道怎么把它变成那种格式。

Dim Year As Integer
Dim Month As Integer
Year = InputBox("Enter the Year", "Year", "YYYY")
Month = InputBox("Enter the Month", "Month", "M")
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "" & Year & Month & "-janusus;import-actual-" & Year & Month & "-R.csv", FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close SaveChanges:=False

我尝试了下面的代码。

ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "" & Year & Format(Month, "0#") & "-janusus;import-actual-" & Year & Month & "-R.csv", FileFormat:=xlCSV, CreateBackup:=False

代码我试图得到工作响应findwindow:

Dim Year As Integer
Dim Month
Dim Month1
Dim Month2
Year = InputBox("Enter the Year", "Year", "YYYY")
Month = InputBox("Enter the Month", "Month", "M")
Month1 = WorksheetFunction.Text(Month), "00")
Month2 = WorksheetFunction.Text(Month), "00")

多亏了findwindow的帮助,我得出了下面的结论,工作完美。我感谢你所有的帮助找到窗口!

Dim Year As Integer
Dim Month1
Dim Month2
Year = InputBox("Enter the Year", "Year", "YYYY")
Month1 = InputBox("Enter the Month", "Month", "M")
Month2 = WorksheetFunction.Text(Month1, "00")
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "" & Year & Month2 & "-janusus;import-actual-" & Year & Month1 & "-R.csv", FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close SaveChanges:=False

相关内容

最新更新