How To Print To PDF With Excel VBA? - Super User
Có thể bạn quan tâm
-
- Home
- Questions
- Tags
- Users
- Jobs
- Companies
- Unanswered
- Teams
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Try Teams for free Explore Teams - Teams
-
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams How to print to PDF with Excel VBA? Ask Question Asked 9 years, 8 months ago Modified 4 years, 1 month ago Viewed 49k times 0As the title suggests... I'm looking to expand my automating to include directly printing to PDF. The macro(s) I have written already formats the print area and page setup as I need it. But when I go to record my macros nothing for printing, changing printers or saving to file is captured.
Is there a way to accomplish this? I could even get by if it just required a save location prompt. The file name I would imagine could be auto-generated by grabbing existing info within the spreadsheet.
Share Improve this question Follow edited Apr 5, 2018 at 2:00 dasMetzger asked Mar 23, 2015 at 18:22 dasMetzgerdasMetzger 1793 gold badges4 silver badges13 bronze badges 0 Add a comment |1 Answer
Sorted by: Reset to default Highest score (default) Date modified (newest first) Date created (oldest first) 2if you are using Excel 2010 and above, then Excel provides you with in internal add-in which allows you to save the file as PDF format. Use the following code in your macro to save your file as PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ "C:\Users\46506090\Desktop\Book1.pdf", Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _ TrueHere you can replace the path C:\Users\46506090\Desktop\Book1.pdf and file name to your liking.
Edit: If you intend to publish the entire workbook as PDF and not just the sheet you are working on just replace ActiveSheet.ExportAsFixedFormat to ActiveWorkbook.ExportAsFixedFormat
Share Improve this answer Follow edited Mar 23, 2015 at 18:36 answered Mar 23, 2015 at 18:30 PrasannaPrasanna 4,1545 gold badges36 silver badges51 bronze badges 4- Will I be able to customize the filename & location based on other content within the worksheet or previously defined by another sub? Also, will this overwrite any file names already present at that location or give me a prompt to rename? Isn't the default usually a (1) after the filename to avoid overwriting existing files? – dasMetzger Commented Mar 23, 2015 at 18:36
- 2 To add to this answer: In my version of this, it saves the PDF file in the same location as the file being printed. fPath = Left(ActiveWorkbook.FullName, InStrRev(ActiveWorkbook.FullName, ".") - 1) & " - " & ActiveSheet.Name & ".pdf" – Engineer Toast Commented Mar 23, 2015 at 18:36
- 2 @dasMetzger Sure, you can customize it. Prasanna hard-coded it but you can change it to a variable and then set that variable anywhere you like. You could even put this snippet into a function with the file path as an argument so you can call it elsewhere. – Engineer Toast Commented Mar 23, 2015 at 18:38
- If you want to use the same filename as the Excel file is - you can add @EngineerToast code – Prasanna Commented Mar 23, 2015 at 18:38
You must log in to answer this question.
Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.Not the answer you're looking for? Browse other questions tagged
.- The Overflow Blog
- Your docs are your infrastructure
- Featured on Meta
- More network sites to see advertising test [updated with phase 2]
- We’re (finally!) going to the cloud!
Related
8 How to fix missing equations in Word 2007 when printing/converting to PDF? 6 How can I print Excel spreadsheet files automatically? 0 Macro to Import CSV files into Excel 3 Adding extra left margin in pdf print without using Acrobat Pro 2 Print many small PDF pages on one regular page 2 Excel doesn't print all active sheets to PDF 1 Can whiteouts in a PDF be undone?Hot Network Questions
- Proof assistants for undergraduate analysis
- Trump's tariff plan
- The sum of multiple irrational numbers can be rational, even when they're not conjugates. Is this normal?
- Deutsche Bahn Berlin: can I use a different departure station?
- How to combine the multiple collections as a collection in geometry node?
- What exactly is the cornerstone that Mark 12:10 speaks of?
- Why is a pure copper cathode necessary in the electrolytic refining of copper?
- Why is it safe to soak an electric motor in isopropyl alcohol but not distilled water?
- Comparing the time duration to do a job
- Walks in Nice (Nizza)
- Table tennis tournament scoreboard
- Is Isaiah's suffering servant the prophet Jeremiah?
- Does length contraction "break the speed limit"?
- p column type stops compilation in RevTeX
- Polynomial.java - a Java class for dealing with polynomials with BigDecimal coefficients
- Do I need Letter of invitation to Iceland?
- How to find file names but only with grep .html OR .php?
- Can this strong directional blur at wide apertures still be explained by the usual arguments?
- When did Storm Troopers stop being clones?
- Are mental images of mathematical entities persistent?
- Angular orientation of exact solution of the Hydrogen Schrödinger Equation
- How to evenly pad columns to make a table fit a specified width
- Schrödinger's cat ++
- I am the owner of an image. I published it in Unsplash. Am I allowed to upload that same image to other sites?
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
lang-vbTừ khóa » Visual Basic Excel Print To Pdf
-
Excel VBA Save As (Print) To PDF
-
How To Print To PDF In Excel VBA : With Examples And Illustrations
-
Print To PDF Using Macro Button In Excel (5 Macro Variants)
-
VBA Print To PDF And Save With Automatic File Name - Stack Overflow
-
How To Print A PDF In Excel VBA? | MrExcel Message Board
-
Excel VBA Save As PDF: Step-By-Step Guide And 10 Examples
-
Excel Macro To Save Sheets As PDF - Contextures
-
VBA For Excel (365), How To Print To PDF, While Scaling To Fit All ...
-
Save Excel As PDF With VBA
-
Excel Print To PDF Vba | PDF | Visual Basic For Applications - Scribd
-
VBA Macro One Click Print To PDF | Strength Coach Tutorials
-
Solved: Print To Pdf From An Excel - Autodesk Community - AutoCAD
-
Cách Chuyển File Excel Sang PDF Sử Dụng VBA - Thủ Thuật
-
Excel Vba Open And Print PDF File - PDFCOFFEE.COM