VBA print to PDF issue on windows 10

androidcreator

New Member
Joined
Oct 16, 2019
Messages
4
Hi,

I'm quite new with VBA coding and need to solicit help from you.

I have an existing coding regarding the print to pdf using adobe acrobat. My laptop was upgraded to windows 10 and the adobe acrobat was removed and changed to microsoft print to pdf. Now my coding didn't work eventhough we installed adobe distiller. this is where the issue pointed me:

Option Explicit

Public WithEvents odist As PdfDistiller

Private Sub Class_Initialize()
Set odist = Nothing
Set odist = New PdfDistiller
End Sub

---------------------------------------------------------------------------------------------------------------------------------------------------------------

sCurrentPrinter = Application.ActivePrinter 'Save the currently active printer
sPDFVersionAndPort = "Adobe PDF on Ne05:"
sPSFileName = myPath & Year(Date) & "-" & DNMonth & "-" & DNFName & ".ps" 'Name of PS file
sPDFFileName = myPath & Year(Date) & "-" & DNMonth & "-" & DNFName & ".pdf" 'Name of PDF


ActiveWindow.SelectedSheets.PrintOut ActivePrinter:=sCurrentPrinter, PrintToFile:=True, PrToFileName:=sPSFileName 'Prints to PS
'ThisWorkbook.Sheets.PrintOut ActivePrinter:=sPDFVersionAndPort, PrintToFile:=True, PrToFileName:=sPSFileName 'Prints to PS

Call appDist.odist.FileToPDF(sPSFileName, sPDFFileName, sJobOptions)

On Error GoTo HERE

'Creates PDF

Kill sPSFileName 'Removes PS
Kill myPath & Year(Date) & "-" & DNMonth & "-" & DNFName & ".log"

Application.ActivePrinter = sCurrentPrinter 'Change back to the original printer

DNNum = DNNum + 1

Set appDist = Nothing



Thank you very much for your help
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Adobe is not required to create a pdf

try this One-Liner

Code:
Sub PDF()
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\results\test.pdf"
End Sub

hth,

Ross
 
Upvote 0
Adobe is not required to create a pdf

try this One-Liner

Code:
Sub PDF()
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\results\test.pdf"
End Sub

hth,

Ross
How would I utilize this with a named range I'm trying to automate printing every morning?
 
Upvote 0
How about ...

VBA Code:
Sub PDF()
    With ActiveSheet
        .PageSetup.PrintArea = Range("YourNamedRange").Address
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\results\test.pdf"
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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