ho fatto questo:
Sub StampaPdf()
Dim FoglioDaStampare As Worksheet
Dim EC As String
EC = "Estratto Conto Leader "
Dim PrimaCellaPivot As Range
Dim PrimaCellaAreaStampa As String
Dim UltimaCellaAreaStampa As String
Dim PathFile As String
Dim NomeFile As String
Dim ArrayCaratteriVietati As Variant
'=== Impostazione riferimenti a fogli e celle ==='
Set FoglioDaStampare = ActiveSheet
With FoglioDaStampare
PrimaCellaAreaStampa = .Range("A1").Address
Set PrimaCellaPivot = .Range("A13")
NomeFile = .Range("B10").Value
End With
PathFile = Application.DefaultFilePath & Application.PathSeparator
'=== Impostazione riferimenti a fogli e celle ==='
With PrimaCellaPivot.CurrentRegion
UltimaCellaAreaStampa = .Cells(.Rows.Count, .Columns.Count).Address
End With
ArrayCaratteriVietati = Array("/", "\", "?", "*", ":", "|", """", "<", ">")
For I = 0 To UBound(ArrayCaratteriVietati)
NomeFile = Replace(NomeFile, ArrayCaratteriVietati(I), "-")
Next I
MsgBox NomeFile
With FoglioDaStampare
.PageSetup.PrintArea = PrimaCellaAreaStampa & ":" & UltimaCellaAreaStampa
On Error Resume Next
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=PathFile & EC & NomeFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End With
Set PrimaCellaPivot = Nothing
Set FoglioDaStampare = Nothing
End Sub
Sub ale()
'*************controllo il DefPath******************
Dim DefPath As String
DefPath = Application.DefaultFilePath
If Right(DefPath, 1) <> "\" Then
DefPath = DefPath & "\"
End If
'*************controllo il DefPath******************
Dim DAA
tec = Cells(2, 9) '21
MsgBox tec
team = Cells(1, 9) '9
'*****controllo se è stato scelto un team o meno*******************
Dim risp
aHelp = "DEMO.HLP"
aCtxt = 1000
If team = 0 Then
risp = MsgBox("Devi selezionare almeno una Branch", vbCritical, "Estratto Conto Leader", aHelp, aCtxt)
Exit Sub
End If
'*****controllo se è stato scelto un team o meno*******************
For I = 1 To team
Range("I4").Select
ActiveCell = "=INDIRECT(""tab!""&ADDRESS(" & tec & ",1))"
DAA = Range("I4")
ActiveSheet.PivotTables("Tabella_pivot1").PivotFields("Tecnico").CurrentPage = _
DDA
StampaPdf
tec = tec + 1
Next I
'messaggio del file creato
Dim lem, Style, Title, Help, Ctxt, Response, MyString
Style = vbOKOnly + vbInformation + vbApplicationModal
Title = "Estratto Conto Tecnici Leader - Rentokil Initial Italia S.p.A."
Help = "DEMO.HLP"
Ctxt = 1000
lem = lem & "Salvataggio completato " & vbLf & vbLf
lem = lem & "i file sono stati creati" & vbLf
lem = lem & "" & vbLf
lem = lem & "li troverai nel tuo path predefinito " & vbLf & vbLf
lem = lem & DefPath & vbLf & vbLf
lem = lem & "Ora puoi inviarli a chi di competenza " & vbLf
Response = MsgBox(lem, Style, Title, Help, Ctxt)
ActiveSheet.PivotTables("Tabella_pivot1").PivotFields("Tecnico").CurrentPage = _
"(Tutto)"
'Range("I4").Delete
End Sub
pare che va...ma non so perchè ogni tanto mi va in errore dentro al for quando do quel DDA al campo tecnico
"impossibile trovare la proprietà PivotFields per la classe PivotTable
oppure altre volte non mi prende il nome del tecnico perchè pare sia blanc per cui mi sovrascrive il file e mi trovo solo l'ultimo...
faccio altre prove.
ciao
ale