Error in vba code (macro) that saves my file in folder?

Jyggalag

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

I have this macro:

1643989999975.png


Once I press the macro "Save file to folder", I get the error above, and debugging it leads me to this:

1643990060509.png


I want to save my file as a PDF file in the path above. Any idea why it does not work and how I can fix it?

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.
When the error occurs, enter the following line in the Immediate Window (Ctrl+G) . . .

VBA Code:
? Path & fn & ".pdf"

Does it return the correct path and filename? And, if so, does the file actually exist in the folder?
 
Upvote 0
Hi
When the error occurs, enter the following line in the Immediate Window (Ctrl+G) . . .

VBA Code:
? Path & fn & ".pdf"

Does it return the correct path and filename? And, if so, does the file actually exist in the folder?
Hi Domenic,

I have never used the Immediate Window. I have typed the code you gave me into it now, but no idea what to do now? if I run the code the error still pops.

P.S. The file path is correct, I just tested it and I can go there through the link from the VBA and see my files.

I have another backup file of this excel document that does work, but once I started recording some macros in this file, it messed up my VBA (even though I have now deleted those macros).

Super weird and really dont get it :(
 
Upvote 0
When the error occurs, enter the following line in the Immediate Window (Ctrl+G) . . .

VBA Code:
? Path & fn & ".pdf"

Does it return the correct path and filename? And, if so, does the file actually exist in the folder?
 
Upvote 0
Ne
When the error occurs, enter the following line in the Immediate Window (Ctrl+G) . . .

VBA Code:
? Path & fn & ".pdf"

Does it return the correct path and filename? And, if so, does the file actually exist in the folder?
I fixed it!

It was because my cell range had moved from A35 to A39. I missed this.

My bad, apologies for the confusion! Very new to VBA and macros :)
 
Upvote 0
Solution

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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