Ciao Domenico,
Sempre restando in ambito fatture, quando salvo le fatture le salvo con il seguente nome : FT (numero fattura) del dd-mm-yyyy (nome cliente) .
Questi dati sono presenti nel foglio excell.
E' possibile automatizzare il salvataggio i modo che va a prendere i dati direttamente sul foglio excell.
Prova qualcosa del genere:
'=========>>
Option Explicit
'--------->.
Public Sub SalvaInPDF()
Dim SH As Worksheet
Dim sPath As String, sStr As String, sFileName As String
Dim sCliente As String, sData As String
Dim sNumeroFattura As String
Const cPrefix As String = "FT("
Const cTesto As String = ") del "
Const cPath As String = "**C:\Utenti\Domenico\Documenti**" '<<==== Modifica
Const cCellaNomeCliente As String = "A1" '<<==== Modifica
Const cCellaData As String = "E1" '<<==== Modifica
Const cCellaNumeroFattura As String = "E2" '<<==== Modifica
Set SH = ActiveSheet
With SH
sCliente = .Range(cCellaNomeCliente).Value
sData = Format(.Range(cCellaData).Value, "dd-mm-yyyy")
sNumeroFattura = .Range(cCellaNumeroFattura).Value
On Error GoTo ErrHandler
With Application
sStr = .PathSeparator
If Right(cPath, 1) = sStr Then
sPath = cPath
Else
sPath = cPath & sStr
End If
End With
sFileName = cPrefix & sNumeroFattura & cTesto _
& sData & " (" & sCliente & ")"
On Error GoTo ErrHandler:
SH.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=sPath & sFileName, _
Quality:=xlQualityStandard, _
OpenAfterPublish:=False
End With
Exit Sub
ErrHandler:
Call MsgBox(Prompt:="Errore " _
& Err.Number _
& " (" _
& Err.Description _
& ") nella routine: SalvaInPDF_1", _
Buttons:=vbCritical, _
Title:="ERRORE")
End Sub
'<<=========
===
Regards,
Norman