Save sheet as PDF

kakiebos

Board Regular
Joined
Jun 10, 2018
Messages
62
Hi.

I have some code that is almost working as I want it to work.

Code:
Sub Job_Card_to_PDF()


  Dim FileDir As String
  Dim PDF As String




  JNo = Range("U18").Value & "; "
  QNo = Range("U19").Value & "; "
  ONo = Range("U20").Value & "; "
  ESN = Range("AP9").Value & "; "
  Fleet = ActiveSheet.Range("AP17").Value
  strTime = Format(Now(), "yyyymmdd-hhmm")
  
  FileDir = "C:\Users\" & Environ$("UserName") & "\Documents\" & "Jobs\"
  PDF = JNo & sQno & QNo & ONo & ESN & Fleet & "  (E-Job Card " & strTime & ").pdf"
  
  
  
  Application.ScreenUpdating = False
  
  ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FileDir & PDF, OpenAfterPublish:=True
  
  Application.ScreenUpdating = True




End Sub

This code will rename the PDF document with information from a couple of different cells.
for example: J1234; Q2345; O5678; 12345678; FL04 (E-Job Card 20190806-1447).pdf
The problem now is when one of or more of the cells is empty then the file name have a bunch of unwanted characters.
for example: J1234; ; ; 12345678; FL04 (E-Job Card 20190806-1447).pdf

How can I use a if statement or isblank statement to get rid of all the unwanted characters?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Here's one way:
Code:
  JNo = Range("U18").Value
  QNo = Range("U19").Value
  ONo = Range("U20").Value
  ESN = Range("AP9").Value
  If JNo <> "" Then JNo = JNo & "; "
  If QNo <> "" Then QNo = QNo & "; "
  If ONo <> "" Then ONo = ONo & "; "
  If ESN <> "" Then ESN = ESN & "; "
  Fleet = Range("AP17").Value
  strTime = Format(Now(), "yyyymmdd-hhmm")
  
  FileDir = "C:\Users\" & Environ$("UserName") & "\Documents\" & "Jobs\"
  PDF = JNo & sQno & QNo & ONo & ESN & Fleet & "  (E-Job Card " & strTime & ").pdf"
 
Upvote 0
Thanks. That works great.
One last thing, ONo and especially Fleet can have some letters and numbers. I want the letters to be in upper case. Even if the user typed it in lower case.
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,287
Members
448,562
Latest member
Flashbond

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