Jyggalag

Active Member
Joined
Mar 8, 2021
Messages
445
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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
See here for code for saving your file as PDF:
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
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
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"
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
You are welcome.
Glad I was able to help.
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,139
Members
453,021
Latest member
Justyna P

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 AdBlock

1)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 Plus

1)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 Origin

1)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 uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top