beneduci55
New member
- Joined
- Jan 1, 2020
- Messages
- 4
- Reaction score
- 0
- Points
- 0
- Excel Version(s)
- 365
Hi all,
I have a lot of experience using the Excel UI, but just recently started dabbling in VBA. I created a recipe template for a chef who wanted a way to "SaveAs" the file with the recipe name without having to type it out every time. Using VBA, I set it to save as FileName = a cell on a hidden sheet which combined the "Recipe Title," "Prep," and today's date as mm.dd.yyyy. The formula looks like this:
=Recipe!C1 & " " & "Prep" & " " & MONTH(Recipe!C42) & "." & DAY(Recipe!C42) & "." & YEAR(Recipe!C42)
I created a FormControl Button to execute the Sub SaveAsTitleDate()
Code follows:
Sub SaveAsTitleDate()
Dim Filename As String
Dim FilePath As String
Dim wsHidden As Worksheet
Set wsHidden = Worksheets("Hidden")
FilePath = ThisWorkbook.Path
Filename = wsHidden.Range("C2")
ActiveWorkbook.SaveAs Filename:=Filename & ".xlsm"
End Sub
This worked great! If I had filled out the title as "Carrot Soup," and clicked the button, it would save as "Carrot Soup Prep 01.01.2020.xlsm." Then, the problems arose. Once I have my "Carrot Soup Prep 01.01.2020.xlsm" file, and I make a change, I am unable to save it again via the button! It triggers a Run-time error '1004.' Cannot access read-only document. Through some online research, I found some codes online that were supposed to resolve this issue, but none of them worked. If you could better advise me, I would really appreciate it.
Thanks and Happy New Year!
I have a lot of experience using the Excel UI, but just recently started dabbling in VBA. I created a recipe template for a chef who wanted a way to "SaveAs" the file with the recipe name without having to type it out every time. Using VBA, I set it to save as FileName = a cell on a hidden sheet which combined the "Recipe Title," "Prep," and today's date as mm.dd.yyyy. The formula looks like this:
=Recipe!C1 & " " & "Prep" & " " & MONTH(Recipe!C42) & "." & DAY(Recipe!C42) & "." & YEAR(Recipe!C42)
I created a FormControl Button to execute the Sub SaveAsTitleDate()
Code follows:
Sub SaveAsTitleDate()
Dim Filename As String
Dim FilePath As String
Dim wsHidden As Worksheet
Set wsHidden = Worksheets("Hidden")
FilePath = ThisWorkbook.Path
Filename = wsHidden.Range("C2")
ActiveWorkbook.SaveAs Filename:=Filename & ".xlsm"
End Sub
This worked great! If I had filled out the title as "Carrot Soup," and clicked the button, it would save as "Carrot Soup Prep 01.01.2020.xlsm." Then, the problems arose. Once I have my "Carrot Soup Prep 01.01.2020.xlsm" file, and I make a change, I am unable to save it again via the button! It triggers a Run-time error '1004.' Cannot access read-only document. Through some online research, I found some codes online that were supposed to resolve this issue, but none of them worked. If you could better advise me, I would really appreciate it.
Thanks and Happy New Year!