Jyggalag

Active Member
Joined
Mar 8, 2021
Messages
445
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi all,

I currently have a macro that saves my sheet as a PDF, however when I try to do this, it brings me this error:

1651133159291.png


If I debug it highlights this in my VBA code:

1651133197834.png



The code is this:

VBA Code:
Option Explicit

Sub SaveFileWithMacro()

Dim Path As String
Dim fn As String
Path = "R:Path\PDF files\"
fn = Range("A39")
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=Path & fn & ".pdf"

End Sub

Can somebody help me fix this issue please? Would be much appreciated! :)
 
As I said yesterday, there's nothing wrong with the code syntax, so it's either environmental (permissions etc) or the values of your variables are not actually valid. If you add a Debug.Print Path & fn line, does the output look correct? Can you copy the path into an explorer window and have it actually open?
Hi Rory,

I fixed the issue!

The issue was that I had the cell, for which the file were saved under, naming the file "XYZ dddd/mm/yy".

However, documents will not allow names to be saved with a backslash in them "/", so this is what caused the issue.

I have amended my formula so it now saves the file as "XYZ dddd-mm-yy" instead :)

Apologies for the confusion and issues, turned out the code was just as you said (of course ;) ). Thank you so much for your help nonetheless, it definitely sped up the process!
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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