Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao essegi75,
vorrei risolvere un problema con un macro VBA per esportare un foglio di un file excel in PDF.
In pratica ho bisogno di esportare un foglio in PDF attribuendo, oltre ad un prefisso (LIC_ORD_), anche una data presa da una cella. Vi allego la macro che mi hanno aiutato a creare:
Sub exp_pdf_ORD()
Set WB = ThisWorkbook
fpath = WB.Path & ""
filenam = "LIC_ORD_"
Sheets("STA_ORD").Copy
fname = fpath & filenam & Format(Sheets("INS_ORD").Range("J10"), "yyyy-mm-dd") & ".pdf"
Sheets("STA_ORD").ExportAsFixedFormat Type:=xlTypePDF, Filename:=fname, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
ActiveWorkbook.Close SaveChanges:=False
End Sub
In pratica nel nome del file ci deve essere la data scritta nella cella J10 del foglio INS_ORD, ma per come è scritta la macro mi dà errore e non riesco a capire quale passaggio è sbagliato
Prova qualcosa del genere:
'=========>>
Option Explicit
'--------->>
Public Sub exp_pdf_ORD()
Dim WB As Workbook
Dim srcSH As Worksheet, nameSH As Worksheet
Dim rngNome As Range
Dim sPath As String, sSuffisso As String, sFilename As String
Const sPrefisso As String = "LIC_ORD_"
Const sFoglioSorgente As String = "STA_ORD"
Const sFoglioNome As String = "INS_ORD"
Const sCellaNome As String = "J10"
Const sEstensione As String = ".pdf"
Set WB = ThisWorkbook
With WB
sPath = .Path & ""
Set srcSH = .Sheets(sFoglioSorgente)
Set nameSH = .Sheets(sFoglioNome)
Set rngNome = nameSH.Range(sCellaNome)
sSuffisso = Format(rngNome.Value, "yyyy-mm-dd")
sFilename = sPath & sPrefisso & sSuffisso & sEstensione
srcSH.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=sFilename, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
.Close SaveChanges:=False
End With
End Sub
'<<=========
Eseguendo il codice, si crea un file pdf con un nome del tipo:
===
Regards,
Norman