Solved

Excel PDF

Posted on 2015-01-29
2
106 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
ID: 40579035
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 49

Expert Comment

by:Rgonzo1971
ID: 40579234
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today companies are subjected to more-and-more data, and it won't stop any time soon.  But there are obvious opportunities for reducing data, particularly data duplicated among companies.
Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

776 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