Macro to create a PDF of an external excel workbook

davidalldred

New Member
Joined
Sep 13, 2016
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi peeps, I am pretty sure that this can be done, but I have no idea where to start so I am hoping someone here can.

What I would like to have is a macro-enabled workbook that will allow you to select another workbook with multiple worksheets and either save it as a PDF or print it to a PDF.

My thoughts of a solution would be to have a Macro Workbook that you open, and you would either put the address into a cell and run the macro or you run the macro and a pop up window opens up and you go to the workbook file location that you want to print to PDF. It would then create, save and open the PDF so that it can be checked.

I know how to create a macro to do this within a workbook, but I don't want to make it into a macro-enabled workbook.

I don't have any examples to attach as it's just an idea I have to make it easy to create PDFs.

Thanks in advance for any solutions.

Dave.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I know how to create a macro to do this within a workbook, but I don't want to make it into a macro-enabled workbook.
You can't have a macro in a workbook without that workbook being macro-enabled.
 
Upvote 0
You can't have a macro in a workbook without that workbook being macro-enabled.
Thanks mump. Yes I know that you need a macro enabled workbook to add macro. What I'm looking for is in effect a user interface that will create a PDF of any excel. I've got a macro that does something similar but it combines the first worksheet in multiple workbooks (not macro enabled) into one workbook. I thought I could adapt this coding to what I need but after trying somethings I can't seem to so I came to the conclusion it can't, and so I posted this.

Dave.
 
Upvote 0
To clarify, you want to select an Excel file and covert it to a PDF file. Is this correct?
 
Upvote 0
@davidalldred So you want a user to select a Workbook that they are not currently using to turn into a PDF?
 
Upvote 0
Change the folder path of the save destination (in red) and the file name (in blue) to suit your needs.
Rich (BB code):
Sub CreatePDF()
    Application.ScreenUpdating = False
    Dim flder As FileDialog, FileName As String, FileChosen As Integer, srcWB As Workbook
    Set flder = Application.FileDialog(msoFileDialogFilePicker)
    flder.Title = "Please Select an Excel File"
    FileChosen = flder.Show
    FileName = flder.SelectedItems(1)
    Set srcWB = Workbooks.Open(FileName)
    ChDir "C:\Test\"
    With ActiveWorkbook
        .ExportAsFixedFormat Type:=xlTypePDF, FileName:="MyFile.pdf"
        .Close False
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Change the folder path of the save destination (in red) and the file name (in blue) to suit your needs.
Rich (BB code):
Sub CreatePDF()
    Application.ScreenUpdating = False
    Dim flder As FileDialog, FileName As String, FileChosen As Integer, srcWB As Workbook
    Set flder = Application.FileDialog(msoFileDialogFilePicker)
    flder.Title = "Please Select an Excel File"
    FileChosen = flder.Show
    FileName = flder.SelectedItems(1)
    Set srcWB = Workbooks.Open(FileName)
    ChDir "C:\Test\"
    With ActiveWorkbook
        .ExportAsFixedFormat Type:=xlTypePDF, FileName:="MyFile.pdf"
        .Close False
    End With
    Application.ScreenUpdating = True
End Sub
Thanks again Mumps. managed to give it go and it is working exactly how I imagined it would (but I am sure you already know this :~) ) thanks for spending the time to resolve, it is appreciated!

Cheers.

Dave.
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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