Solved

Excel PDF

Posted on 2015-01-29
2
108 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 51

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hi all how do i achive this formula in condtional formatting excel 6 66
Globalscape EFT Notifications Help 2 56
Need public domain maps 3 74
NAS ISCSI Sharing 8 87
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…
All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Viewers will learn how to use the Hootsuite Dashboard.

710 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