Ciao Sebastiano Di Paola,
un modo:
' Nel modulo Visual Basic del Foglio di lavoro in cui è presente
' il Pulsante di comando di nome "cmdStampaPDF"
'
Option Explicit
' La routine evento del pulsante "cmdStampaPDF"
'
Private Sub cmdStampaPDF_Click()
' Il percorso e il nome con cui verrà salvato il file PDF:
Const cstrPathFilePdf = "D:\Percorso\Nome.pdf" ' <-- Modificare!
' Il nome del Foglio di lavoro da stampare:
Const cstrFoglio = "Foglio2" ' <-- Modificare!
' La cella in cui c'è il numero di pagine da stampare:
Const cstrPagg = "K1" ' <-- Modificare!
' La cella in cui ci sono le coordinate dell'area di stampa.
' Per esempio, in Foglio2, cella K2, ho immesso: A1:J159
Const cstrArea = "K2" ' <-- Modificare!
Dim wsh As Excel.Worksheet
Dim strArea As String
Dim lngPagg As Long
Set wsh = ThisWorkbook.Worksheets.Item(cstrFoglio)
lngPagg = wsh.Range(cstrPagg).Value
Debug.Print lngPagg
strArea = wsh.Range(cstrArea).Value
Debug.Print strArea
With wsh
' Impostazioni di stampa da cambiare in base alle necessità.
' La cosa migliore da fare è registrare una macro poi copiare
' da quella i valori.
With .PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
.PrintArea = strArea
.LeftHeader = "&""-,Grassetto"" Confidenziale"
.CenterHeader = ""
.RightHeader = "&D"
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = "Pagina &P di &N"
.LeftMargin = Application.InchesToPoints(0.393700787401575)
.RightMargin = Application.InchesToPoints(0.393700787401575)
.TopMargin = Application.InchesToPoints(0.393700787401575)
.BottomMargin = Application.InchesToPoints(0.393700787401575)
.HeaderMargin = Application.InchesToPoints(0.31496062992126)
.FooterMargin = Application.InchesToPoints(0.31496062992126)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = -3
.CenterHorizontally = True
.CenterVertically = False
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 999
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
.ExportAsFixedFormat Type:=xlTypePDF _
, Filename:=cstrPathFilePdf _
, Quality:=xlQualityStandard _
, IncludeDocProperties:=True _
, IgnorePrintAreas:=False _
, From:=1 _
, To:=lngPagg _
, OpenAfterPublish:=True
End With
Set wsh = Nothing
End Sub