Hi keebeelah,
I tried but there is a 438 error with the line:
Application.PrintCommunication = False
I have excel 2007 and this does not work.
I found a solution on the net:
On Error Resume Next
Application.PrintCommunication = False
Err.Clear
Option Explicit
Public Sub stampa_foglio() '<<< ookkk
Dim pRange1 As String
Dim pRange2 As String
Dim pLoop As Integer
'ActiveSheet.Unprotect "123456" 'password
ActiveSheet.Protect "123456", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFiltering:=True, UserInterFaceonly:=True
pRange1 = "$A$1:$L$206"
pRange2 = "$A$207:$L$217"
Application.ScreenUpdating = False
For pLoop = 1 To 2
On Error Resume Next
Application.PrintCommunication = False
Err.Clear
'Application.PrintCommunication = False
Select Case pLoop
Case Is = 1
ActiveSheet.PageSetup.PrintArea = pRange1
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$5"
.PrintTitleColumns = ""
End With
Selection.AutoFilter Field:=1, Criteria1:="<>"
Case Is = 2
ActiveSheet.PageSetup.PrintArea = pRange2
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$3"
.PrintTitleColumns = ""
End With
End Select
'Application.PrintCommunication = True
On Error Resume Next
Application.PrintCommunication = True
Err.Clear
'ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWindow.SelectedSheets.PrintPreview
Next pLoop
On Error Resume Next
Application.PrintCommunication = False
Err.Clear
'Application.PrintCommunication = False
ActiveSheet.PageSetup.PrintArea = pRange1
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$5"
.PrintTitleColumns = ""
End With
Selection.AutoFilter Field:=1
Application.ScreenUpdating = True
'With ActiveSheet.PageSetup
'.LeftHeader = Application.UserName 'nome in alto a dx
'.CenterHeader = ""
'.RightHeader = ""
'.LeftFooter = Format(Date, "dddd dd/mm/yyyy") 'data in basso a sx
'.CenterFooter = ""
'.RightFooter = Foglio1.Range("E1").Text 'riferimento cella E1
'End With
'ActiveSheet.Protect "123456" 'password
'ActiveSheet.Protect "123456", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFiltering:=True, UserInterFaceonly:=True
End Sub
everything works now.
The macro is perfect.
Greetings and thank you very much.
max
Bookmarks