+ Reply to Thread
Results 1 to 7 of 7

How to save activeworkbook in created folder

  1. #1
    Registered User
    Join Date
    12-25-2010
    Location
    Rotterdam
    MS-Off Ver
    Excel 2010
    Posts
    18

    How to save activeworkbook in created folder

    why won't it accept de var500 discription??
    The backup needs to be in the created strFolder
    The MkDir works and creates the folder/map.
    Now I want the active workbook to be saved in this newly created folder/map.


    MkDir ("P:\QC\LAB errors 2013\" & strFolder)
    var500 = strFolder
    ChDir "P:\QC\LAB Errors 2013\& var500"
    ActiveWorkbook.SaveAs Filename:= _
    "P:\QC\LAB Errors 2013\& var500\BackupGC.xls", FileFormat:=xlNormal, _
    Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
    CreateBackup:=False

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: How to save activeworkbook in created folder

    Hi, Harrij,

    if itīs a variable you must tell VBA so and not include it in "" (VBA wonīt reckognize it there as a variable but only as a string):
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    12-25-2010
    Location
    Rotterdam
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: How to save activeworkbook in created folder

    Did the following........... what else do i need to in VBA ??? HOW do I make this context work???


    Dim var500
    sub backup()
    MkDir ("P:\QC\LAB errors 2013\" & strFolder) ..................WORKS !
    var500 = strFolder................ STATES VAR500="BACKUPGCFEB".....so okay
    ChDir "P:\QC\LAB Errors 2013\" & var500........................ here no way ... path unknown?????
    ActiveWorkbook.SaveAs Filename:= _
    "P:\QC\LAB Errors 2013\" & var500 & "\BackupGC.xls", FileFormat:=xlNormal, _
    Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
    CreateBackup:=False
    end sub

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: How to save activeworkbook in created folder

    Hi, Harrij,

    where does the variable strFolder get the value? If you are currently not on the drive you need to change the drive first and only after that you may change the folder:
    Please Login or Register  to view this content.
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code in [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    12-25-2010
    Location
    Rotterdam
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: How to save activeworkbook in created folder

    Did the following........... what else do i need to in VBA ??? HOW do I make this context work???


    Dim var500
    sub backup()
    MkDir ("P:\QC\LAB errors 2013\" & strFolder) ..................WORKS !
    var500 = strFolder................ STATES VAR500="BACKUPGCFEB".....so okay
    ChDir "P:\QC\LAB Errors 2013\" & var500........................ here no way ... path unknown?????
    ActiveWorkbook.SaveAs Filename:= _
    "P:\QC\LAB Errors 2013\" & var500 & "\BackupGC.xls", FileFormat:=xlNormal, _
    Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
    CreateBackup:=False
    end sub

  6. #6
    Registered User
    Join Date
    12-25-2010
    Location
    Rotterdam
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: How to save activeworkbook in created folder

    I am already on the P: drive and var500= strFolder is already defined earlier in the script and has a working var !

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: How to save activeworkbook in created folder

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code in [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Josie

    if at first you don't succeed try doing it the way your wife told you to

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1