I originally have this code to save name and save a file when I click on a control button and it works great. Here is the code:
So then I tried creating another one but get an error message. The error says:
Compile error in hidden module: Module2. This error commonly occurs when code is incompatible with the version, platform, or architecture of this application. Click "Help" for information on how to correct this error.
Here is the code I have so far:
Sub Auto_Save_File()
If [B2] = "" Then
MsgBox "Please Enter Monday's Date In This Format MM/DD/YY." & vbNewLine & _
"Then Click Auto Save Button."
[B2].Select
Exit Sub
End If
Dim yr As String
Dim mnth As String
Dim dd1 As String
Dim dd2 As String
Dim fname As String
yr = Right(Range("B2"), 4)
mnth = Left(Range("B2"), 2)
dd1 = Left(Range("B2"), 3, 2)
dd2 = Left(Range("Z2"), 3, 2)
fname = "C:\Users\JD\Desktop\" & Format(DateValue & yr & "_") _
& mnth & "_" & dd1 & "-" & dd2 & ".xlsm"
ActiveWorkbook.SaveAs Filename:=fname
End Sub
This is coded for a control button I created. User types in dates into cells B2 and Z2 in this format mm/dd/yyyy. I would like the file to save as "2022_09_05-09.xlsm" if the user types 09/05/2022 in cell B2 and 09/09/2022 in cell Z2. Basically naming the file for this week from Monday 05 through Friday 09. I didn't understand how capture dd1 and dd2 strings so the ranges might be off. Can someone please assist or correct this code? Thanks for the help.
VBA Code:
If [C2] = "" Or [G2] = "" Then
MsgBox "Please Select The Month And Year From Drop Down List." & vbNewLine & _
"Then Click The Create File Button."
Exit Sub
End If
Dim mnth As String
Dim fname As String
mnth = Left(Range("C2"), 3)
fname = "C:\Users\JD\Desktop\ECITATIONS_" & Format(DateValue(mnth & "-01"), "mm") _
& mnth & "_" & Range("G2") & ".xlsm"
ActiveWorkbook.SaveAs Filename:=fname
So then I tried creating another one but get an error message. The error says:
Compile error in hidden module: Module2. This error commonly occurs when code is incompatible with the version, platform, or architecture of this application. Click "Help" for information on how to correct this error.
Here is the code I have so far:
Sub Auto_Save_File()
If [B2] = "" Then
MsgBox "Please Enter Monday's Date In This Format MM/DD/YY." & vbNewLine & _
"Then Click Auto Save Button."
[B2].Select
Exit Sub
End If
Dim yr As String
Dim mnth As String
Dim dd1 As String
Dim dd2 As String
Dim fname As String
yr = Right(Range("B2"), 4)
mnth = Left(Range("B2"), 2)
dd1 = Left(Range("B2"), 3, 2)
dd2 = Left(Range("Z2"), 3, 2)
fname = "C:\Users\JD\Desktop\" & Format(DateValue & yr & "_") _
& mnth & "_" & dd1 & "-" & dd2 & ".xlsm"
ActiveWorkbook.SaveAs Filename:=fname
End Sub
This is coded for a control button I created. User types in dates into cells B2 and Z2 in this format mm/dd/yyyy. I would like the file to save as "2022_09_05-09.xlsm" if the user types 09/05/2022 in cell B2 and 09/09/2022 in cell Z2. Basically naming the file for this week from Monday 05 through Friday 09. I didn't understand how capture dd1 and dd2 strings so the ranges might be off. Can someone please assist or correct this code? Thanks for the help.