PDA

View Full Version : Save As function randomly replaces my file path, Error 1004



Cheesecube
05-16-2020, 07:15 AM
Hi, I have a file located at C:\A\B\C\macro.xlsm

I want to save my data to C:\A\B\D\save.xlsx

So I use the string ThisWorkbook.Path & "\..\D\save.xlsx"
with a \..\ to move one level up

I used a MsgBox to confirm that the string is "C:\A\B\C\..\D\save.xlsx"

Somehow, when I use the SaveAs function, it says it cannot access the file C:\A\B\D\9CD78...
or something like this. Run-time error 1004

Every time I run it the save location is replaced with some random hexadecimal code

What went wrong and how do I make this SaveAs function work?

Cheesecube
05-16-2020, 08:08 AM
I tested this out and found that this happens only if the folder path has not been created when I save the file to a particular location.

How do I write the code so that it creates the folder path to the save location if it does not exist yet?

paulked
05-17-2020, 07:51 AM
This (https://www.extendoffice.com/documents/excel/4182-excel-check-if-folder-exists.html) should help you sort that out :thumb

Paul_Hossler
05-17-2020, 08:21 AM
My old eyes almost missed the fact that "This" was a link


https://www.extendoffice.com/documents/excel/4182-excel-check-if-folder-exists.html

paulked
05-17-2020, 08:35 AM
:rofl: My apologies