Save File As PDF In VBA (macro)? | MrExcel Message Board

MrExcel Message Board
  • Forums New posts Search forums Board Rules
  • What's new New posts New Excel articles Latest activity
  • New posts
  • Excel Articles Latest reviews Search Excel articles
  • MrExcel Publishing MrExcel Homepage MrExcel Bookstore MrExcel Seminars Excel Consulting Services
Log in Register What's new Search

Search

Everywhere Threads This forum This thread Search titles only By: Search Advanced search…
  • New posts
  • Search forums
  • Board Rules
Menu Log in Register Install the app Install How to install the app on iOS

Follow along with the video below to see how to install our site as a web app on your home screen.

Note: This feature may not be available in some browsers.

  • If you would like to post, please check out the MrExcel Message Board FAQ and register here. If you forgot your password, you can reset your password.
  • Forums
  • Question Forums
  • Excel Questions
You are using an out of date browser. It may not display this or other websites correctly.You should upgrade or use an alternative browser. Save file as PDF in VBA (macro)?
  • Thread starter Jyggalag
  • Start date Feb 2, 2022
  • Tags &indexdd code conditional formatting email excel help if formula iferror index indexmatch jyggalag match save as pdf vba vba code vlookup yonasreppenk
Jyggalag

Jyggalag

Active Member
Joined Mar 8, 2021 Messages 424 Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi all, I currently have the following setup: 1643809105483.png I have marked everything that I want to be exported into a PDF, which works when I manually save the file as a PDF. However, I do also have a macro ("Save file to folder") as seen above, which saves the file (albeit as an Excel file) to my folder My code for this macro (VBA) IS: VBA Code: Sub SaveFileWithMicro() Dim Path As String Dim fn As String Path = "\\COMPANY.MSSS.COMPANY.NET\userdata\t6853425\home\Documents\TEST tracking files\Track with macro\" fn = Range("A35") ActiveWorkbook.SaveAs Filename:=Path & fn & ".xls", FileFormat:=xlNormal End Sub If I want to edit this VBA so it saves my files as a PDF, does anybody know of a nice way in which this could be done? Would truly appreciate some assistance here! Many thanks :) Kind regards, Jyggalag

Excel Facts

Fastest way to copy a worksheet? Click here to reveal answer Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet. Sort by date Sort by votes Joe4

Joe4

MrExcel MVP, Junior Admin
Joined Aug 1, 2002 Messages 72,822 Office Version
  1. 365
Platform
  1. Windows
See here for code for saving your file as PDF: exceloffthegrid.com

How to save Excel as PDF with VBA (10 examples)

This post shows how to save Excel as PDF with a VBA macros. With 10 examples, you will learn how to automate your work and save time. exceloffthegrid.com exceloffthegrid.com Upvote 0 Jyggalag

Jyggalag

Active Member
Joined Mar 8, 2021 Messages 424 Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Joe4 said: See here for code for saving your file as PDF: exceloffthegrid.com

How to save Excel as PDF with VBA (10 examples)

This post shows how to save Excel as PDF with a VBA macros. With 10 examples, you will learn how to automate your work and save time. exceloffthegrid.com exceloffthegrid.com Click to expand...
Hi Joe, Thank you so much! I tried the formula (to implement it into mine), but I get this error? 1643810570984.png Can you see what I am doing wrong? Upvote 0 Jyggalag

Jyggalag

Active Member
Joined Mar 8, 2021 Messages 424 Office Version
  1. 365
  2. 2019
Platform
  1. Windows
N
Joe4 said: See here for code for saving your file as PDF: exceloffthegrid.com

How to save Excel as PDF with VBA (10 examples)

This post shows how to save Excel as PDF with a VBA macros. With 10 examples, you will learn how to automate your work and save time. exceloffthegrid.com exceloffthegrid.com Click to expand...
Note: It says this when I try to run the macro: 1643810602660.png Upvote 0 Joe4

Joe4

MrExcel MVP, Junior Admin
Joined Aug 1, 2002 Messages 72,822 Office Version
  1. 365
Platform
  1. Windows
You just assigned the Path to the filename argument, but NEVER gave it a file name! I think you want it to end: VBA Code: Filename:=Path & fn & ".pdf" Upvote 0 Solution Jyggalag

Jyggalag

Active Member
Joined Mar 8, 2021 Messages 424 Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Joe4 said: You just assigned the Path to the filename argument, but NEVER gave it a file name! I think you want it to end: VBA Code: Filename:=Path & fn & ".pdf" Click to expand...
It works!! Thank you so much Joe! :) Full code for anybody wondering: VBA Code: Option Explicit Sub SaveFileWithMacro() Dim Path As String Dim fn As String Path = "\\COMPANY.NFDS.COMPANY.NET\userdata\t5435234\home\Documents\TEST tracking files\Track with macro\" fn = Range("A35") ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, _ Filename:=Path & fn & ".pdf" End Sub And apologies for the confusion :) I have quite a hard time wrapping my head around VBA. I understand most of everything above now however! Upvote 0 Joe4

Joe4

MrExcel MVP, Junior Admin
Joined Aug 1, 2002 Messages 72,822 Office Version
  1. 365
Platform
  1. Windows
You are welcome. Glad I was able to help. Upvote 0 You must log in or register to reply here.

Similar threads

S
  • Question
Macro to change one cell on a sheet, save sheet as PDF, then loop back and change that one cell on that sheet and repeat until the end
  • SMRXIV
  • May 14, 2024
  • Excel Questions
Replies 3 Views 284 Jun 18, 2024 IslandofBDA I A
  • Solved
3 way use button to run macro
  • Aleytha
  • Apr 16, 2024
  • Excel Questions
Replies 2 Views 236 Apr 16, 2024 Aleytha A M
  • Question
Excel VBA Save PDF within workbook folder and send as email attachment
  • maxbrggs
  • Mar 12, 2024
  • Excel Questions
Replies 1 Views 637 Mar 12, 2024 rpaulson rpaulson I
  • Question
Help with VBA script please
  • indiglo
  • May 27, 2024
  • Excel Questions
Replies 3 Views 210 Jun 2, 2024 jolivanes jolivanes V
  • Question
Excel VBA - How to modify my code to include a command that prints data to PDF
  • VanGirl
  • Apr 16, 2024
  • Excel Questions
Replies 1 Views 305 Apr 16, 2024 VanGirl V Share: Facebook X (Twitter) Reddit Pinterest Tumblr WhatsApp Email Share Link

Forum statistics

Threads 1,218,233 Messages 6,141,307 Members 450,347 Latest member Santoli3

Share this page

Facebook X (Twitter) Reddit Pinterest Tumblr WhatsApp Email Share Link
  • Forums
  • Question Forums
  • Excel Questions

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock1)Click on the icon in the browser’s toolbar.2)Click on the icon in the browser’s toolbar.2)Click on the "Pause on this site" option. Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus1)Click on the icon in the browser’s toolbar.2)Click on the toggle to disable it for "mrexcel.com". Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin1)Click on the icon in the browser’s toolbar.2)Click on the "Power" button.3)Click on the "Refresh" button. Go back

Disable uBlock

Follow these easy steps to disable uBlock1)Click on the icon in the browser’s toolbar.2)Click on the "Power" button.3)Click on the "Refresh" button. Go back Continue without adsI've disabled my adblock Back Top

Từ khóa » Visual Basic Excel Save As Pdf