Condividi tramite

Impostazione automatica Area di Stampa in base alle celle Piene

Anonimo
2015-12-02T18:27:57+00:00

Buona sera a tutti

Excel prevede la possibilita' di impostare l'area di stampa automaticamente solo per l'area che contiene dati ??

Sto' cercando di impostare la stampa di etichette su Fogli A4  e il nr. di etichette e' variabile e puo' occupare piu' fogli ,....adesso

ogni volta devo selezionare nella tabella l'area di interesse  e dare imposta area di stampa .... se me ne dimentico ....

Grazie                     Claudio P

Microsoft 365 e Office | Excel | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento

Risposta accettata dall'autore della domanda

Anonimo
2015-12-03T08:33:07+00:00

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

La risposta è stata utile?

0 commenti Nessun commento

2 risposte aggiuntive

Ordina per: Più utili
  1. Anonimo
    2015-12-05T10:04:08+00:00

    Ciao Claudio,

    Grazie anche a te per il cortese riscontro.

     Buon weekend.

    ===

    Regards,

    Norman

    La risposta è stata utile?

    1 persona ha trovato utile questa risposta.
    0 commenti Nessun commento
  2. Anonimo
    2015-12-05T08:42:08+00:00

    GRAZIE   NORMAN

    Buon Week End

                         Ciao    Claudio P

    La risposta è stata utile?

    0 commenti Nessun commento