Solved

Excel PDF

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

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The advancement in technology has been a great source of betterment and empowerment for the human race, Nevertheless, this is not to say that technology doesn’t have any problems. We are bombarded with constant distractions, whether as an overload o…
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

630 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