(Solved) – +1, save “original name”, then make the next save be a compliation of strings


thanks for your help in the past and future.

item 1.
anytime the the file opens I want cell G5 to increase by 1 each time.
then I want the file to save.

item 2.
anytime someone clicks save I want the filename to be a collection of strings.

my code for item 1 works and my code for item 2 works, but when I try to use both it’s not saving after opening so my count is not progressing.

Private Sub Workbook_Open()

Range("G5") = Range("G5")   1


End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim Path As String

Application.EnableEvents = False
Cancel = True

Dim FileName1 As String
Dim Filename2 As String
Dim Filename3 As String
Dim Filename4 As String

FileName1 = Range("C3").Text
Filename2 = Range("C4").Text
Filename3 = Range("G4").Text
Filename4 = Range("G5").Text
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "" & FileName1 & "." & Filename2 & "." & 
Filename3 & "." & Filename4 & ".xlsx", FileFormat:=xlOpenXMLWorkbook
Application.DisplayAlerts = True

End Sub

Thank you

more info…
My big picture goal is to have a TEMPLATE file that can be opened to create a new order with a unique order number. I also want to ensure that if someones opens it and just clicks save that proper naming procedures are followed and the original TEMPLATE is preserved.

I could make the save as code be a workbook close event, but I want to make sure that the template isn’t saved over accidentally.

Leave a Reply

Your email address will not be published. Required fields are marked *