Save as XLS and PDF

MWalton

New Member
Joined
Jun 1, 2011
Messages
3
Hello All,

I am looking to make a macro that will save my current workbook as an XLS and a PDF.

To save as an XLS I am currently using,

Code:
Sub Save()
    ThisFile = Range("B7").Value
    ActiveWorkbook.SaveAs Filename:=ThisFile
End Sub
This is working great for me, but I haven't found a macro yet that will take the file name from the XLS and just save as a PDF. Also, if at all possible, I would like to have a short key in there to make it all quicker, but if not that is fine

Thanks,

Matt
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try...

Code:
[font=Courier New][color=darkblue]Sub[/color] SaveAsPDF()

    [color=darkblue]Dim[/color] ThisFile [color=darkblue]As[/color] [color=darkblue]String[/color]
    
    ThisFile = Range("B7").Value
    
    ActiveWorkbook.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=ThisFile, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=[color=darkblue]False[/color]
        
[color=darkblue]End[/color] [color=darkblue]Sub[/color][/font]

For a shortcut key...

1) Press Alt+F8

2) Select the macro called 'SaveAsPDF'

3) Select 'Options'

4) Enter your shortcut key

5) Click Ok
 
Last edited:
Upvote 0
Thanks a lot for the response, the macro works great!

Is it possible to have one macro that saves an XLS and a PDF at the same time? Using 2 works fine, but having 1 to do both would be awesome

Thanks
Matt
 
Upvote 0
Try...

Code:
[font=Courier New][color=darkblue]Sub[/color] Save()

    [color=darkblue]Dim[/color] ThisFile [color=darkblue]As[/color] [color=darkblue]String[/color]
    
    ThisFile = Range("B7").Value
    
    ActiveWorkbook.SaveAs Filename:=ThisFile, FileFormat:=52
    
    ActiveWorkbook.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=ThisFile, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=[color=darkblue]False[/color]
        
[color=darkblue]End[/color] [color=darkblue]Sub[/color][/font]

Change the FileFormat, accordingly.
 
Upvote 0
Code:
Sub Save()

    Dim ThisFile As String
    
    ThisFile = Range("B7").Value
    
    ActiveWorkbook.SaveAs Filename:=ThisFile, xls:=52
    
    ActiveWorkbook.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=ThisFile, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=False
        
End Sub

When I use that, I get an error that reads,
'Can't execute code in break mode'

Matt
 
Upvote 0
Try replacing...

Code:
xls:=52

with

Code:
FileFormat:=51   'Workbook default

or

FileFormat:=-4143  'Workbook normal
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,710
Members
452,939
Latest member
WCrawford

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