question

SheliaCarr-7509 avatar image
0 Votes"
SheliaCarr-7509 asked emizhang-msft commented

How can I keep a two digit number that contains a zero in the file name when saving the file?

I created an inputbox where the user would need to enter a two digit code. The number from the inputbox is then used when saving the file as .csv file, however, the number is being changed to "1" instead of "01". How can I correct my code where the number format remains two digits when it's preceded by 0?

The format for my file name should be MTPO_20210305_USERID-01_2021 but it's being saved as MTPO_20210305_USERID-1_2021

Sub SaveFiles()

Dim MySavePath As Variant
Dim UserID As Variant
Dim MyFileName As String
Dim message As Integer
Dim MyYear As Integer
Dim MyMonth As Integer
Dim MyDay As Integer

MyYear = Year(Now)
MyMonth = Month(Now)
MyDay = Day(Now)


UserID = Application.InputBox(Prompt:="User-ID", Title:="Enter your UserID", Default:="Should be your TSO not your AIN")
message = MsgBox("Is This Correct?", vbInformation + vbYesNo, "You Entered: " & UserID)

inputValue = Application.InputBox("Upload Number", "Please enter a 2 digit sequence number for this upload.", , , , , , 1)

Select Case message
Case vbYes
Case vbNo

End Select


MySavePath = "C:\Users\Documents\Upload Automation\Test Upload Location"
ActiveWorkbook.SaveAs Filename:=
MySavePath & "\" & "MTPO
" & Format(Now, "yyyymmdd") & "" & UserID & "-" & inputValue & "" & MyYear & MyData & ".csv", FileFormat:=xlCSV



End Sub

office-excel-itpro
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SheliaCarr-7509 avatar image
0 Votes"
SheliaCarr-7509 answered emizhang-msft commented

Never mind, I figured it out.
I had to include Format(inputValue, "00") in my file name.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for sharing solution and Accept as answer, other partners who read the forums with the same issue can get more information from the correct result.

0 Votes 0 ·