I'm trying to Save the current file, then Save As to a new filename (for the new quarter/period) prior to clearing the data from the previous quarter/period. I want the user to be prompted for the SaveAs filename and path, but I'd like a default filename to populate in the prompt window using data from a user form (I know this user form is not in the current code below, but I can fix that easily). I'd like to use Me.TextBox1 (year) and Me.TextBox2 (period/quarter #), such as "TLD 2018 P4". Btw, the "TLD" and "P" are not included in the textbox values.
I found a GetSaveAsFilename sample in the Excel Help, but it doesn't work. I keep getting an error that highlights the "fName =" line, and I think I recall it saying that it is a mismatch error. Also, this sample doesn't do anything about a default filename. Thanks for the help!
I found a GetSaveAsFilename sample in the Excel Help, but it doesn't work. I keep getting an error that highlights the "fName =" line, and I think I recall it saying that it is a mismatch error. Also, this sample doesn't do anything about a default filename. Thanks for the help!
Code:
Sub TLDChangeOut()Dim fName As Long
Dim msg As String
Dim Lr As Long
Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("Main Data")
Lr = ws1.Range("A" & Rows.Count).End(xlUp).Row
msg = "Are you sure?@@All TLD numbers and issue/collectiondates will be permanently deleted!"
Select Case MsgBox(Replace(msg, "@", vbCrLf), vbYesNoCancel + vbCritical, "TLD Changeout Confirm")
Case Is = vbYes
ActiveWorkbook.Save
Do
fName = Application.GetSaveAsFilename
Loop Until fName <> False
ActiveWorkbook.SaveAs Filename:=fName
Sheets("Main Data").Range("C7:D" & Lr, "G7:G" & Lr).ClearContents
Case Is = vbNo, vbCancel
End Select
End Sub