Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Claudio,
In un modulo standard, incolla:
'=========>>
Option Explicit
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional Rng As Range)
If Rng Is Nothing Then
Set Rng = SH.Cells
End If
On Error Resume Next
LastRow = Rng.Find(What:="*", _
after:=Rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
'--------->>
Public Function LastCol(SH As Worksheet, _
Optional Rng As Range)
If Rng Is Nothing Then
Set Rng = SH.Cells
End If
On Error Resume Next
LastCol = Rng.Find(What:="*", _
after:=Rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End Function
'<<=========
Nel modulo ThisWorkbook, incolla il seguente codice di evento:
'=========>>
Option Explicit
'--------->>
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim SH As Worksheet
Dim Rng As Range
Dim LRow As Long, LCol As Long
For Each SH In ThisWorkbook.Windows(1).SelectedSheets
LRow = LastRow(SH)
LCol = LastCol(SH)
Set Rng = SH.Range("A1").Resize(LRow, LCol)
SH.PageSetup.PrintArea = Rng.Address(external:=True)
Next SH
End Sub
'<<=========
In questo modo non potresti 'dimenticare', perchè l'area di stampa verrà stabilita automaticamente ogni volta che uno o più fogli vengano stampati
===
Regards,
Norman