It's not clear why you "can't" add these steps but as I intimated in my comment you already have the code to do that.
Having looked at this again, you may be having problems because your code entirely relies on having the correct sheet active in the workbook when it runs. Always explicitly state which sheet you are referring to and that should avoid the problem e.g.
Sub SalvaFile()
Dim wkA As Worksheet, ur As Long, j As Long, riga As Long, nomeFile As String
Dim wkB As Worksheet: Set wkB = Worksheets("Sheet1")
Dim percorso As String
Set wkA = Worksheets("Scadenziario")
wkA.Range("A2:T" & Rows.Count).ClearContents
ur = wkB.Range("A" & Rows.Count).End(xlUp).Row
riga = 2
percorso = "C:\Users\Itaerxga\Desktop\Scadenziari\"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error GoTo errori
For j = 2 To ur
wkB.Cells(j, 1).EntireRow.Copy wkA.Cells(riga, 1)
riga = riga + 1
If wkB.Cells(j, 5) <> wkB.Cells(j + 1, 5) Then
nomeFile = wkB.Cells(j, 5)
wkA.Copy
ActiveWorkbook.SaveAs Filename:=percorso & nomeFile & ".xlsx"
ActiveWorkbook.Close
wkA.Range("A2:T" & Rows.Count).ClearContents
riga = 2
End If
Next j
wkA.Range("A2:T" & Rows.Count).ClearContents
<s>wkA.Range("$A$2").Select</s>
wkA.Range("$A$2").Show
esci:
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "Copiato"
Exit Sub
errori:
MsgBox Err.Number & " - " & Err.Description
Resume esci
End Sub
You are also relying on the workbook with this code never becoming active - have a look at this sub-routinePublic
Sub Demo()
Dim countWbs As Integer
countWbs = Workbooks.Count
Dim i As Integer, wkb As Workbook
For i = countWbs To 1 Step -1
Set wkb = Workbooks(i)
If wkb.Name <> ThisWorkbook.Name Then
wkb.Activate
Debug.Print wkb.Name
wkb.Close
End If
Next
End Sub
Things to note:
- because I am using the index to the workbooks collection I have to start at the end and work backwards (so that book number 1 is always at position 1 and is always the same workbook even after one is closed)
- the Activate is not necessary if I explicitly refer to wkb in whatever I am doing
- I make sure I don't close the workbook that contains my code!