Can anyone help me with a VBA code to convert Excel to PDF, using CutePDF Writer?

henry fam

New Member
Joined
Nov 25, 2013
Messages
15
Basically, I have a folder with 20 excel files (each excel file has only 1 spreadsheet). I want to convert them to PDF with the same names as the excel files are. We use CutePDF Writer.
Can anyone help me with a VBA code?
Thank you so much.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
This should get you moving

Code:
Sub CreatePDF()
'
' PDF generating Macro
'
'
On Error GoTo CreatePDFErr
    
    Dim strTheFileSaveName As String
    
    strTheFileSaveName = Application.GetSaveAsFilename(InitialFileName:="My_" & ActiveWorkbook.Name, _
    filefilter:="PDF (Adobe PDF) (*.pdf), *.Pdf", Title:="Please enter PDF filename to export to")
    
    If strTheFileSaveName = "False" Then
        MsgBox "PDF creation aborted  no file will be produced ", , "Pdf Creation"
        Exit Sub
    End If
    
    
    Application.ScreenUpdating = False
    Sheets("pdf").Visible = True
    Sheets("pdf").Select
    Range("B3:E33").Activate
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strTheFileSaveName, _
        Quality:=xlQualityMinimum, IncludeDocProperties:=False, IgnorePrintAreas:=True, OpenAfterPublish:=False
    
    gblstrPDFName = strTheFileSaveName
    
    Application.ScreenUpdating = True
    
    Exit Sub
    
CreateTPDFErr:
    
    MsgBox "Error returned from PDF creation. " & vbNewLine & "Error is : " & Str(Err) & " " & Error & vbNewLine & "Please Contact your support Staff with this Information", , "PDF Creation"
    Application.ScreenUpdating = True
    
    Exit Sub
    
    End Sub
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,637
Latest member
Ezio2866

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