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, 9 months ago Modified 4 years, 3 months 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
- How AI apps are like Google Search
- Featured on Meta
- The December 2024 Community Asks Sprint has been moved to March 2025 (and...
- Stack Overflow Jobs is expanding to more countries
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
- Why does the engine prefer a5 (pass pawn) over axb5 (pass pawn+win a pawn)?
- Why don't bicycles have the rear sprocket OUTSIDE of the frame spacing? (Single speed)
- Are their any advanatges of a lower value of a loss function?
- Why do we define the standard error to ignore bias (unlike MSE which includes bias)?
- What is the best way to prevent this ground rod from being a trip hazard
- How do I recreate these shooting stars?
- writing two matrices in a clear and nice way
- Is this 240V compressor plug wired correctly?
- Electrician installed NEMA 14-50R 240V receptacle and circuit without ground wire
- When does a noun take the accusative rather than dative form
- meaning of "last time out"
- 2 network cards on 1 ubuntu server netplan config
- Is there a cause of action for intentionally destroying a sand castle someone else has built on a public beach?
- How to Modify 7447 IC Output to Improve 6 and 9 Display on a 7-Segment
- How can I document that I am allowed to travel to the UK from Scandinavia using eVisa/BRP? (Denied at the check-in counter)
- First instance of the use of immersion in a breathable liquid for high gee flight?
- Advanced TAPL Linear Lambda Calculus
- Air launch separation mechanism
- Is this position possible to have been made legally?
- Image of the sun on Yehoshua’s grave?
- The MC dies a few years after an apocalypse, but wakes up years earlier, just days before it starts. Uses his knowledge to gain skills faster
- Download a file with SSH/SCP, tar it inline and pipe it to openssl
- Free Kei Friday
- Adiabatic Interaction in QFT scattering
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