Problem: Windows(CurrentFileName).Activate not executed in the second piece of code, although everything is in order in the first piece of code. That is, the CurrentFileName variable in the second version is empty. What could be the reason? - Tell me please.
Dim M3_FullPath As String, CurrentFileName As String CurrentFileName = ActiveSheet.Parent.name 'Piece of code 1
Windows(M3_FileName).Activate Sheets("M3").Select ActiveSheet.Unprotect Password:=Password ActiveSheet.Range("$A$1:$Q$1048576").AutoFilter ActiveSheet.Range("$A$1:$Q$1048576").AutoFilter Field:=1, Criteria1:=ArrayTM, Operator:=xlFilterValues n = Range("A1").End(xlDown).Row Range("B2:Q" + CStr(n)).Copy Windows(CurrentFileName).Activate Sheets(nameM3).Range("B2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False 'Piece of code 2
Windows(M3_FileName).Activate Sheets("ТИ").Select ActiveSheet.Unprotect Password:=Password ActiveSheet.Range("$A$1:$P$1048576").AutoFilter ActiveSheet.Range("$A$1:$P$1048576").AutoFilter Field:=1, Criteria1:=ArrayTM, Operator:=xlFilterValues n = Range("A1").End(xlDown).Row Range("B2:P" + CStr(n)).Copy Windows(CurrentFileName).Activate Sheets(nameDI).Range("B2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False Application.CutCopyMode = False