Print to PDF writer and save with custom file name

cubbydaniel

New Member
Joined
May 28, 2010
Messages
3
I have been using this print code but now they want me to save it with longer file name

Loan #_ document id_ document id _ document id_time stamp.pdf

I get the idea of changing the printer but what i dont get is how to get the underlines and how do i tell it to save it with those different document ids i am limited to how many values i can have.



Sub Printsheet()
Sheets("Notes").Range("a1:l91").Select
Application.ActivePrinter = "Microsoft XPS Document Writer on Ne00:"
ThisFile = Range("o6").Value
ThisFile2 = Range("o7").Value2
FileDrive = "C:\Users\El Gordo\Desktop\new folder\"
Selection.PrintOut Copies:=1, ActivePrinter:= _
"Microsoft xps Document Image Writer on ne00:", Collate:=True, _
printtofile:=True, prtofilename:=FileDrive & ThisFile & ThisFile2 & ".xps"
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Welcome to the Board.

That code is printing to an xps file not a pdf file. What pdf software do you have? To put an underscore in the file name with your existing code:

Code:
Selection.PrintOut Copies:=1, ActivePrinter:= _
"Microsoft xps Document Image Writer on ne00:", Collate:=True, _
printtofile:=True, prtofilename:=FileDrive & ThisFile & "_"  & ThisFile2 & ".xps"
 
Upvote 0
I have changed the Printer that i am going to use and the file is saved in the destination is supposed to and saved correctly but when i open the file its telling me the file is corrupted is my code wrong.

Sub Printsheet()
Sheets("Notes").Range("a1:l91").Select
Application.ActivePrinter = "CutePDF Writer on CPW2:"
ThisFile = Range("O6").Value
ThisFile2 = Range("O7").Value2
FileDrive = "L:\lslm\vazquezd\TIFF files\"
Selection.PrintOut Copies:=1, ActivePrinter:= _
"CutePDF Writer on CPW2:", Collate:=True, _
printtofile:=True, prtofilename:=FileDrive & ThisFile & "_" & ThisFile2 & "_" & Format(Date, "mmddyyyy") & Format(Time(), "hhmmss") & ".pdf"
viewdocumentimage = False
End Sub
 
Upvote 0
That won't work. Print to file is only applicable to physical printers - the device driver is used to create the file for printing later (using the DOS COPY command). It won't create a true pdf file.

I don't think it's possible to bypass the file name dialog with CutePDF. You best bet is to use PDFCreator.
 
Upvote 0
i was advised to :
Use print like it's physical printer, not printtofile

So do i just change this line
printtofile:=True
change to
Print: = True
Do you know if this is correct?
 
Upvote 0
Andrew,

I installed the PDFCreator as uou suggested. When I print an Excel sheet to it, it creates the file (no dialog box in use)

However, It will not open. It has the message
-----------------
Adobe reader could not open "RemakeForm1_AutoComplete.pdf" because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)
-------------------

There are (as I am sure you are aware of) several threads dealing with this issue

Here is my (test) code

Code:
Sub Create_PDF()
    With ActiveSheet
 
        .PageSetup.PrintArea = "$A$4:$AB$52"
 
        .PrintOut ActivePrinter:="PDFCreator", PrToFileName:=ThisWorkbook.Path & "\" & Left(ThisWorkbook.Name, InStr(ThisWorkbook.Name, ".") - 1) & "_" & .Name & ".pdf"
    End With
End Sub

Thanks in advance
 
Upvote 0
Dear Andrew,

Thanks for your help on this matter.

When I try to use the code after downloading PDFCreator, I get a compile error message saying that "User defined type not defined" for PDFCreator.clsPDFCreator.

Please guide.

Sanjeev
 
Upvote 0

Forum statistics

Threads
1,214,849
Messages
6,121,922
Members
449,056
Latest member
denissimo

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