Forum Discussion
Anonymous
Jul 27, 2018Export Excel worksheet to PDF using cell value make a filename
Dear all, I'm making an invoice system most of the functions work good so far but I got stuck in this one. Private Sub CommandButton2_Click() Sheets("Pakbon").ExportAsFixedFormat Type:=x...
Haytham Amairah
Jul 27, 2018Silver Contributor
Hi Nico,
To get access to a specific cell value in a specific sheet, you can use the Value property of Range object in VBA as below example:
Sheets("Pakbon").Range("A1").Value
Let's say that the project number is in cell A1, so please update the code as follows:
Private Sub CommandButton2_Click()
Dim path As String
path = "C:\Users\Mann\Desktop\NaLeveringTool\" & Sheets("Pakbon").Range("A1").Value & _
"Pakbon_" & _
Format(Now(), "dd-mm-yyyy_hh_mm") & ".pdf"
Sheets("Pakbon").ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=path
End Sub
Regards