+ Reply to Thread
Results 1 to 13 of 13

Save to Different Directory

  1. #1
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Save to Different Directory

    Hello, could some one please help me modify the code below? The Kill function works OK but the ThisWorkbook.SaveAs part does not work for some reason.

    Please note that there are 2-spaces between the words: P3 CATS

    Any assistance would be greatly appreciated.

    Kind regards,

    Chris

    Please Login or Register  to view this content.
    Last edited by longbow007; 02-03-2010 at 05:47 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Save Excel Workbook to different Directory

    Hello longbow007,

    I am still looking through my documentation, but I believe it is because you are attempting to save the workbook during the Workbook_BeforeClose event.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208

    Re: Save to Different Directory

    Well, the code as written appears fine. And it works for me after I created the appropriate directories. My guess is that you may have mistyped the directory. Although I did not test it in the Workbook_BeforeClose event.

    You could turn off the error handling and see what type of error you get.

    HTH,
    Jason

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Save to Different Directory

    I tested the Workbook_BeforeClose event with a Thisworkbook.saveas and it worked fine for me.
    Is there a reason why you use the kill command for a file you are about to save over anyway?
    Why not use activeworkbook.saveas instead of thisworkbook.saveas?
    Should you need those parentheses for the argument in your saveas function?
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Save to Different Directory

    Maybe like this:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Save to Different Directory

    Please Login or Register  to view this content.
    You will hate yourself the day you make some disastrous mistake, plan to close the file without saving, and then it gets saved anyway.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: Save to Different Directory

    Hi JBeaucaire, thank you for your code - very much appreciated. It's probably me, but the active workbook for some strange reason does not get save in the directory:

    C:\CAT\MEALS\CATS Litters\P3 CATS\Databases\Backup\

    What I used to do is Kill the file in the above directory and then save the active workbook in it.

    I have tried many things to get this to work such as turning off the error handling, checked the spelling of the directory and tried using activeworkbook.saveas

    If you could please further assist - that would be terrific.

    Cheers,

    Chris.

  8. #8
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: Save to Different Directory

    Hi JBeaucaire,

    I tried to google my problem and came across the following website:

    http://msdn.microsoft.com/en-us/library/h1e33e36.aspx

    I tried using the:

    Application.ActiveWorkbook.SaveCopyAs("C\Book1.xls")

    and just changed the directory path and file name to suit.

    This save method seems to work OK.

    I am not sure why this method works but the SaveAs method does not.

    I thought you may be interested in the final result.

    Thanks again for your help.

    Cheers,

    Chris.

  9. #9
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: Save to Different Directory

    Hi JBeaucaire,

    I tried to google my problem and came across the following website:

    http://msdn.microsoft.com/en-us/library/h1e33e36.aspx

    I tried using the:

    Application.ActiveWorkbook.SaveCopyAs("C\Book1.xls")

    and just changed the directory path and file name to suit.

    This save method seems to work OK.

    I am not sure why this method works but the SaveAs method does not.

    I thought you may be interested in the final result.

    Thanks again for your help.

    Cheers,

    Chris.

  10. #10
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: Save Excel Workbook to different Directory

    Thank you Leith Ross for your kind assistance - very much appreciated.

    Cheers,

    Chris.

  11. #11
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: Save to Different Directory

    Thank you jasoncw for your help - I did previously disable error handling and checked my typing of the pathway and directory. I had no luck there. It's all fixed now.

    Cheers,

    Chris.

  12. #12
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: Save to Different Directory

    Hi davegugg, thanks for your help, I used the kill method to delete the old backup copy of my workbook out of its folder. Seems to work very well. I did try the ActiveWorkbook.SaveAs method but had no luck with it. It is all fixed now.

    Cheers,

    Chris.

  13. #13
    Forum Contributor
    Join Date
    06-13-2009
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    245

    Re: Save to Different Directory

    thank you shg for your help. I was trying to save a copy of my active workbook into a separate directory. Appreciate your assistance.

    Kind regards,

    Chris.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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