Consulting

Results 1 to 5 of 5

Thread: Save As function randomly replaces my file path, Error 1004

  1. #1

    Automatically create folder path to SaveAs location if it does not exist yet?

    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?
    Last edited by Cheesecube; 05-16-2020 at 08:11 AM.

  2. #2
    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?

  3. #3
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    This should help you sort that out
    Last edited by paulked; 05-17-2020 at 08:35 AM.
    Semper in excretia sumus; solum profundum variat.

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    My old eyes almost missed the fact that "This" was a link


    https://www.extendoffice.com/documen...er-exists.html
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    My apologies
    Semper in excretia sumus; solum profundum variat.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •