Solved

Excel PDF

Posted on 2015-01-29
2
104 Views
Last Modified: 2015-02-26
How to I create a simple macro to save various worksheet ranges in an excel file to a PDF and also refer to a cell reference in the naming of the file
0
Comment
Question by:ToddMuch
2 Comments
 
LVL 7

Accepted Solution

by:
Deadman earned 500 total points
Comment Utility
Assuming that you have Excel 2007 or later:
Press Alt+F11 to activate the Visual Basic Editor.
Select Insert | Module.
Copy the following code into the module window:

Sub SavePDF()
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
        Filename:="C:\PDF\Export.pdf", _
        OpenAfterPublish:=False
End Sub

Open in new window


Change the path and filename as desired.

Switch back to Excel.
Activate the Developer tab of the ribbon.
Click Insert > Button (Form Control)(This is in the Form Controls section of the Insert dropdown).
Click on the worksheet.
Excel will display the Assign Macro dialog.
Select SavePDF in the list of macros, then click OK.
You'll see a small button on the sheet.
Right-click it to edit its text.

Then click outside the button to activate it.
0
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,

pls try something like this

ActiveSheet.Range("A1:B10,A25:B30").ExportAsFixedFormat Type:=xlTypePDF, _
        Filename:="C:\Export" & Range("A1").Value & ".pdf", _
        IgnorePrintAreas:=False, OpenAfterPublish:=True


'if multiple sheets

ThisWorkbook.Sheets(Array("Sheet1", "Sheet2")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
        Filename:="C:\Export" & Range("A1").Value & ".pdf", _
        IgnorePrintAreas:=False, OpenAfterPublish:=True

Open in new window

Regards
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now