VBA to save PDF

Status
Not open for further replies.

kakiebos

Board Regular
Joined
Jun 10, 2018
Messages
62
Hi.

I have a spreadsheet that is used as a electronic job card. After the job, it needs to be exported as a PDF and saved with the job number, quote number and order number in the file name. Example: JNo003; QNo007; ONo1234 - Todaysdate
Sometimes the quote number or the order number is not available then I want to save it without those numbers to look like this: JNo003; ONo1234 - todaysdate

The Job number is in this format: "J / No 003" for the file name to work I need to remove the " / " to look like "JNo003" in the file name

I'm newish to VBA and are stuck. Especially with the if/case part of my problem. I also have a workaround on the spreadsheet to remove the " / " by using hidden cells with formulas in there.

I'm pretty sure there are someone with more experience to assist me to do this easier and faster.

Thanks in advance.
NB: I've copied and pasted my code here. Not sure if this is the correct way.

Currently my code looks like this:
Sub SavePDF

Dim FileDir As String
Dim PDF As String
Dim QNo As String
Dim JNo As String
Dim ONo As String

JNo = Range("I18")
QNo = Range("I19")
ONo = Range("I20")
FileDir = "C:\Users" & Environ$("UserName") & "\Documents" & "Jobs"


PDF = Job_No & "; " & QNo & "; " & ONo & " - " & "E-Job Card " & _
strTime & ".pdf"

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FileDir & PDF, OpenAfterPublish:=True

End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Thread closed at OP's request
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,213,543
Messages
6,114,236
Members
448,555
Latest member
RobertJones1986

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top