tinamiller1
New member
- Joined
- Aug 28, 2013
- Messages
- 16
- Reaction score
- 0
- Points
- 0
I am trying to create a beforesave code within my template. The template has certain fields that are blank and when the end user enters data, I want them to be able to click on save or the blue disk and it saves it to a new location, based on their user and some of the cells within the form. I do not want the template to be saved with the data they input. The data they input is saved only when they click the blue disk and it saves to another location, with their username and certain cells in the form. Then the end user can continue using that same template for the next entry and so on. I have a beforeclose that asks them if they really want to close or not. The only time they would close, or hit the big red X is when they are done with all their entries for the day. Here is my code for my beforesave:
****someone else suggested putting in a read only, but not sure where to put that in the beforesave and the below code does not work. it gives me an error of run-time 1004 method saveas of object workbook failed.
****someone else suggested putting in a read only, but not sure where to put that in the beforesave and the below code does not work. it gives me an error of run-time 1004 method saveas of object workbook failed.
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="C:\Users\" & Environ$("username") & _
"\Documents\Audits\Excels\" & Range("B9").Text & Chr(32) & Range("B7").Text & _
Chr(32) & Format(Range("B10").Value, "MM-DD-YYYY") & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.DisplayAlerts = True
End Sub