Solved

Excel PDF

Posted on 2015-01-29
2
105 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ERD Visio 2010 Drawing - Table Relationships 4 98
Win 7 OS unable to install Win updates 3 136
PCAnywhere 2 95
Need a poor man's PowerPoint 5 72
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

932 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

10 Experts available now in Live!

Get 1:1 Help Now