Sub CreaPdf()
On Error GoTo Gest_err
Rows("24:28").Select
Selection.EntireRow.Hidden = True
Application.Wait TimeSerial(Hour(Now), Minute(Now), Second(Now + TimeValue("00:00:01")))
Set FSO = CreateObject("Scripting.FileSystemObject") ' New FileSystemObject
strTempPath = FSO.GetSpecialFolder(TemporaryFolder) & "" & FSO.GetTempName & ""
FSO.CreateFolder strTempPath
SetAttr (strTempPath), vbHidden
ChDir strTempPath
Dim arrPos(2000)
T = Range(A16)
x = 3
y = 1
Do While (Sheets("DB_Anagrafica_Mese").Cells(x, 49) <> "")
If Sheets("DB_Anagrafica_Mese").Cells(x, 49) <> "." Then
Range("A16") = Sheets("DB_Anagrafica_Mese").Cells(x, 49)
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"Indicatori" & " " & Sheets("DB_Anagrafica_Mese").Cells(x, 50) & " " & Sheets("DB_Anagrafica_Mese").Cells(x, 49) & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
x = x + 1
T = T + 1
Else
Exit Do
End If
Loop
Z = y
y = 1
Do While Z > 1
For n = 1 To Z
x = arrPos(n)
Range("A16") = Sheets("DB_Anagrafica_Mese").Cells(x, 49)
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"Indicatori" & " " & Sheets("DB_Anagrafica_Mese").Cells(x, 50) & " " & Sheets("DB_Anagrafica_Mese").Cells(x, 49) & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Next
Z = y
y = 1
Loop
Range("A16") = ""
q = 3
w = 1
Do While (Sheets("DB_Anagrafica_Mese").Cells(q, 49) <> "")
If Sheets("DB_Anagrafica_Mese").Cells(q, 49) <> "." Then
Range("A16") = Sheets("DB_Anagrafica_Mese").Cells(q, 49)
Dim NewMail As Object
Set NewMail = CreateObject("Outlook.Application").CreateItem(oMailItem)
With NewMail
.To = Worksheets("DB_Anagrafica_Mese").Cells(q, 51)
.CC = Sheets("Cruscotto").Cells(28, 2)
.Subject = "Indicatori"
.Body = Sheets("Cruscotto").Cells(26, 2)
.Attachments.Add strTempPath & "Indicatori" & " " & Sheets("DB_Anagrafica_Mese").Cells(q, 50) & " " & Sheets("DB_Anagrafica_Mese").Cells(q, 49) & ".pdf"
.Display
.Save
.Send
End With
q = q + 1
Else
Exit Do
End If
Loop
j = w
w = 1
Do While j > 1
For r = 1 To j
q = arrPos(r)
Range("A16") = Sheets("DB_Anagrafica_Mese").Cells(q, 49)
With NewMail
.To = Worksheets("DB_Anagrafica_Mese").Cells(q, 51)
.CC = Sheets("Cruscotto").Cells(28, 2)
.Subject = "Indicatori"
.Body = Sheets("Cruscotto").Cells(26, 2)
.Attachments.Add strTempPath & "Indicatori" & " " & Sheets("DB_Anagrafica_Mese").Cells(q, 50) & " " & Sheets("DB_Anagrafica_Mese").Cells(q, 49) & ".pdf"
.Display
.Save
.Send
End With
Next
j = w
w = 1
Loop
Range("A16") = ""
Rows("24:28").Select
Selection.EntireRow.Hidden = False
Range("A15").Select
'Pulizie
Set appOL = Nothing
Set creaEmail = Nothing
Kill (strTempPath & "*.*")
RmDir (strTempPath)
Exit Sub
Gest_err:
arrPos(y) = x
y = y + 1
Resume Next
End Sub |