Save Excel Sheet as PDF with Simple Macro – ExcelVbaIsFun

Get My Bestselling Excel VBA Courses:
Excel VBA Essentials Course:
Control Websites With Excel VBA:
Speed Up Code With VBA Arrays:
Create Your Own Functions/Addins:
Fill PDFs/Forms with Excel VBA:
Excel VBA Barcode Lookup System & Inventory Projects:
Instantly Secure Excel Files; Transform Into EXE Programs!:
Professional Animations In Excel by Kishon:

Fantastic Developer Tools:
Lock Any Workbook Into An EXE (Software only, see course above):
Create Custom Installers:

Free Ebook:
Dan Strong’s Articles:
Free Excel Workbooks:
Business Inquiries, Consulting, Comments, etc:

ExcelVbaIsFun YouTube Playlists:
Excel Vba Basics:
Tips N Tricks:
Userforms:
Events Series:
Activex Controls:
Sample Excel Programs:

Where else you can find me:
LinkedIn:
Facebook:
Twitter:
Google Plus+:

T-Shirts/Merch:

‘Royalty Free Music by

Nguồn: https://vmmotorsdaihan.com

Xem thêm bài viết khác: https://vmmotorsdaihan.com/tong-hop/

37 Comments

Mancing Gamer

July 5, 2020

How to save pdf with save dialog.? Please

Reply

Mancing Gamer

July 5, 2020

How to create Excel to word documen

Reply

Pankaj Verma

July 5, 2020

Thank you so much for your kind help!

Reply

Genevieve Wilson

July 5, 2020

Hello! Quick question, when I print my excel sheets to the pdf it cuts off the last three columns and prints them onto a separate page. How can program my code to force a "fit to page"/"shrink to fit" or at least have some control over what is cut off?

Reply

welcome dosti

July 5, 2020

an error , show xlTypePDF =0 what to do

Reply

Sinan Basha - سنان باشا

July 5, 2020

Hi.
pls can u help me with ( doing auto organization chart with vba ) .

Reply

Jon Michael Schiavone

July 5, 2020

very helpful but can you not record your trial and error process? thanks

Reply

Pieter van Zetten

July 5, 2020

If I want to make the filename dynamic like celvalue D13 followed by cellvalue D12 + date of today. How sould I add this in to the Macro?

Reply

Bigg Red

July 5, 2020

how do you make the file name save in different names

Reply

Luciano Martinez

July 5, 2020

got a question, i can print several documents through a sort of loop from a data validation list which is great. but i want to have the ability to saveaspdf as well. let me show you my code i have for printing through an iteration. maybe you can help me do the same for saveaspdf through a sort of iteration of some kind:

Sub Iterate_Through_data_Validation()
Dim xRg As Range
Dim xCell As Range
Dim xRgVList As Range
Set xRg = ActiveSheet.Range("D1")
Set xRgVList = Evaluate(xRg.Validation.Formula1)
For Each xCell In xRgVList
xRg = xCell.Value
ActiveSheet.PrintOut
Next
End Sub

Reply

Mary Madyarova

July 5, 2020

Hello, do you know how to get and change coordinates of a specific text (Ex. "Figure 1" in the right coner of page, for example) on a PDF page. PDF page has only text. I am writing VBA code and cannot figure it out.

Reply

SHRIDHAR B

July 5, 2020

I'm Beginner in VB, Its very helpful in my off work. Thank you a lot

Reply

akash shinde

July 5, 2020

Sir I have use this code in vba. But error display on screen is "Run-time error 15, Invalid procedure call or argument ". Kindly guide me solve this error. And also I have check the code is many times,.

Reply

AsaDosT

July 5, 2020

Hi sir
I am new to Excel vba & I often view yr vids, i need help for printer. I have to 2 computer in my office 1 is Prh-Pc & 2 is Asad-pc. Epson Printer is installed on 1pc & another receipt printer installed no2 PC. My Epson printer is connected to no2pc via dongle (same network). The problem is I want to change my default receipt printer to Epson Printer, when I save the PDF file with command button it saves in receipt printer format which is very long, I want to change to Epson printer in A4 size.how to code for it

Reply

K.R.Sathya Narayanan

July 5, 2020

Hi…. Really thanks for this video, I was finding this one line for whole day, Finally i made it because of this video, Thanks for making my day peaceful.

Reply

Ben Mathews

July 5, 2020

Can you please explain on how to have the file name change based on a cell in the actual document? This is what I am struggling with.

Reply

Sudipta Ghosh

July 5, 2020

Every time when Trying to save .xlsm file to .pdf through macro button, the existing file was replacing with new one. how can I prevent it as I want to save files in different name. pls help…

Reply

Meyyammai Thiagarajan

July 5, 2020

is it possible to export password protected PDFs

Reply

MD ANWAR FAIZI

July 5, 2020

USEFULL

Reply

Ed Salavarria Jr

July 5, 2020

When I made the macro. It only overwrites it when I save. How do I make it save a whole new file name every time I run the macro? Thank you.

Reply

Chris Keo

July 5, 2020

how do you add a user form to enter a name you want for the file and another user form to choose a directory

Reply

Maggie Thinyane

July 5, 2020

hey there can you please help me. what am i doing wrong with this formula;sumnth =  application.WorksheetFunction.SumProduct(–(MOD(COLUMN(.range("A" & LastRo & ":O" & LastRo))-COLUMN(.range("A" & lastRo))+1,2)=0),.range("A" & LastRo & ":O" & LastRo))

i get the error is "Expected expression"

Reply

Sam

July 5, 2020

This works great, I have my spreadsheet saving as a PDF file using a button, however, how do I get it so it saves a new file every time I click it instead of saving over the previous file?? please help

Reply

swethan kurakula

July 5, 2020

I am able to create the pdf without protecting it with password but i am looking to save file with pdf and password protected, when i do that i am not able to enable password. Can you show me how to record macro using password enabled macro…??please

Reply

Konstantinos Papanikolaou

July 5, 2020

SOLVED FROM ME!!!!
for everyone who may need this!!!

 Sub export2pdf()
'
' export2pdf Macro
'
'
ThisWorkbook.Sheets(Array("a ian", "b ian", "a feb", "b feb", )).Select
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ActiveWorkbook.Path & Application.PathSeparator & "15imera" & Format(Date, "ddmmyyyy")

End Sub
———————-
SOLUTION:
change" Selection.Export…" to "Activesheet.Export…"

 Here is the situation:
In main .xslb file I have multiple sheets like above. Everything works great except one thing: it exports ONLY the 1st pages of each sheet and not all the pages of each sheet.
example:
in sheet "a ian" there is only one page
in sheet "b ian" there are 3 pages
etc…
but it gives me in pdf file only the 1st page of each sheet.
Any help from you?
Thank you for your time.

Reply

Stijn Johannes Wilhelmus 't Jong

July 5, 2020

Hi there, great explanation! I want to do the same thing; wrote a macro to convert a table and the graph it creates to a 1 page PDF. For some reason, it will save the table, though it won't save the graph. Strange right? I do this on my work, so when I switch computers with my colleague and log in to my own account, it suddenly does work and I have table with graph on a 1 page PDF. Unfortunately it has to work on my PC as well (as we our own in the office), do you know what I can do? Thank you so muc in advance!

Reply

yiwen foong

July 5, 2020

Thank you so much! Works perfect

Reply

Ashish Maheshwari

July 5, 2020

Hey.. Suppose. I want to save the file name as "Standard-Today's date". How can i make it dynamic? I can link it to a cell name?

Reply

Meithilesh Ramautar

July 5, 2020

Thank you loads sirji

Reply

Sony M

July 5, 2020

Hello, i have a question. How do i save multiple PDF files of one excel worksheet alone using vba? I tried for loop, but it doesn't seem to work

Reply

Taylor Battistella

July 5, 2020

Thanks, but i can't get it to work properly, because when i am on the visual basic editor, i cannot seem to gt the code to come up at the bottom. WHY?

Thanks so much!

Reply

Onegod007

July 5, 2020

@ExcelVbaIsFun Is there a way to get a macro to work where it prints an output report for each employee, that is based off of a table of values, to a single PDF file instead of cycling and printing a separate PDF file for each employee.  here is the code as it stands. It works well except when I try to print all to PDF and have to individually save 214 PDFs because it wont batch print all records in one PDF.

PSP Rpts

STEP()

=ECHO(FALSE)

=SET.NAME("CNUM",INPUT("Enter
number of copies to be printed.",1,"PSP Reports",1,100,100))

=SELECT(!$C$10)

=IF(ISBLANK(ACTIVE.CELL()),GOTO(A13))

=SELECT("R[1]C")

=GOTO(A10)

=SET.NAME("NUM",ROW(ACTIVE.CELL())-10)

=WORKBOOK.SELECT("PSP
Output","PSP Output")

=FORMULA.FILL(1,!$T$1)

=IF(NUM>!$T$1,GOTO(A19))

=SELECT(!$A$1:$S$42)

=GOTO(A20)

=SELECT(!$A$1:$S$42)

=SET.PRINT.AREA()

=PRINT(1,1,1,1,FALSE,FALSE,1,FALSE,1)

=SET.NAME("CNT",!$T$1+1)

=IF(CNT>NUM,GOTO(A27))

=FORMULA.FILL(CNT,!$T$1)

=GOTO(A16)

=SET.NAME("CNUM",CNUM-1)

=IF(CNUM>0,GOTO(A15))

=WORKBOOK.SELECT("INPUT","INPUT")

=SELECT(!$A$1)

=RETURN()

Reply

Tony Diaz

July 5, 2020

Ok, here's a difficult question for you and has nothing to do with this thread…
I'll just paste the question I did in another place with no success:
Ok, pros out there, I have a good one for you.
I have 28 textboxes; I've created a class module named grpTextbox, and declared my textbox group with the WithEvents keyword.
Now, I want to set an event, BeforeUpdate on my textbox group.
Here's the thing, when I try to invoke this event, out does not show it on the dropdown list; how the hell do I access the damn event for the group of textboxes; if I declare it as MsForms.TextBox I'm fudged, if I declare it as MsForms.Control, bam!! There's the freaking event, but does not work; at runtime I get a stupid 459 error!!
I've seen countless threads about this and no one can figure it out…
Can someone help please!!!!

Thanks and hope someone can figure this one out….

Reply

fisnik hoxha

July 5, 2020

Hi, Dan @ExcelVbaIsFun 
    I wondered if you could show me that when I press a cell it could do a specific role, (ex. open a calculator or anything else.) 
 Thanks,
Fisnik

Reply

Clifton Mcreynolds

July 5, 2020

Hello Dan – great video, could you expand on making the file name dynamic? Maybe post the code? That would be great. 🙂 Thank you.

Reply

Wasim Akram

July 5, 2020

i need a macro to send email with Attachments from excel as mentioned procedure  To address in A column   ,  CC address  in  B Column ,Subject -text in C Column ,Attachment  path in D Column ,Message-text  in  E column  and it should save it on outlook Drafts  please do the need full in this regards expecting your best results on this

Reply

Cleon

July 5, 2020

Hi Dan @ExcelVbaIsFun ! I've always lookup your videos throughout my learning process of Excel!
I was wondering if you could help me in my situation. I currently have a Pie Chart, and i want my Pie Chart to rotate 360 Degree whenever my checkbox is ticked. When unticked, the Pie Chart will stop at its original position. Is this even feasible? If it is, hope you could give me some advice!
Cheers!
Cleon

Reply

Leave a Reply