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! :)
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
What precisely is in A39 on the active sheet?

Edit: just noticed your path is missing a backslash after the colon
 
Upvote 0
Hi
What precisely is in A39 on the active sheet?

Edit: just noticed your path is missing a backslash after the colon
Please ignore the path, I just inserted something to hide my actual path, I think the path is alright

In A39 the cell is blank actually, well spotted!

I cant remember if im supposed to have something here, this is an old file I dug up, can you tell based on the code?
 
Upvote 0
What precisely is in A39 on the active sheet?

Edit: just noticed your path is missing a backslash after the colon
I think it is the cell that names what the file should be named.

however, if I change this to A51 (which is the correct cell, dont know why it was changed), it still gives me an error:

1651136256068.png


And debug highlights this:

1651136282740.png
 
Upvote 0
The code itself is fine, so there is either something wrong with the path (doesn't end in a backslash for example) or the file name, or you don't have permission to write to that location.
 
Upvote 0
Solution
The code itself is fine, so there is either something wrong with the path (doesn't end in a backslash for example) or the file name, or you don't have permission to write to that location.
that is so weird

the path is 100% fine I am sure of this and nobody has the PDF open

never seen this error before and no idea how to fix :(
 
Upvote 0
Does a PDF with that name already exist at the specified location?
 
Upvote 0
Does a PDF with that name already exist at the specified location?
I don't think so,

It saves the name with a number rather than as a PDF.

However, I tried removing all the PDF files and it still did not work, even with an empty folder
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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