+ Reply to Thread
Results 1 to 6 of 6

Automatically Saving A Workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    07-05-2006
    Posts
    7

    Automatically Saving A Workbook

    I would like to be able to save a workbook using a macro, that will save the file in a particular loaction e.g. C:\My Documents\Spreadsheet Files\Example Spreadsheet.xls and have the directory created for those users for whom it does not exist.

    I would also like the file to be named according to the contents of cell c2 on a sheet named "list"

    Any help would be much appreciatted.

  2. #2
    markwalling
    Guest

    Re: Automatically Saving A Workbook

    answers? no. guidance to where you could find help on using the file
    system? yes:

    the visual basic help file is pretty useless to beginers, but if you
    are pointed in the right direction it can be very valuable.

    here is a technical article from msdn about the FileSystemObject. that
    should be a good starting place. Most of the methods are linked in the
    msdn, otherwise type it into visual basic and hit F1.

    any more questions feel free to post them.

    MW

    "if you give a man a fish, you feed him for a day. if you teach a man
    to fish, you feed him for a lifetime."


    Papa Waigo wrote:
    > I would like to be able to save a workbook using a macro, that will save
    > the file in a particular loaction e.g. C:\My Documents\Spreadsheet
    > Files\Example Spreadsheet.xls and have the directory created for those
    > users for whom it does not exist.
    >
    > I would also like the file to be named according to the contents of
    > cell c2 on a sheet named "list"
    >
    > Any help would be much appreciatted.
    >
    >
    > --
    > Papa Waigo
    > ------------------------------------------------------------------------
    > Papa Waigo's Profile: http://www.excelforum.com/member.php...o&userid=36074
    > View this thread: http://www.excelforum.com/showthread...hreadid=558861



  3. #3
    Tom Ogilvy
    Guest

    RE: Automatically Saving A Workbook


    Sub SaveFile()
    Dim s as String, sName as String
    s = "C:\My Documents\Spreadsheet Files\"
    On Error Resume Next
    Mkdir "C:\My Documents"
    MkDir "C:\My Documents\Spreadsheet Files"
    On Error goto 0
    sName = ActiveWorkbook _
    .Worksheets("List").Range("c2").Text & ".xls"
    if dir(s & sName) <> "" then
    kill s & sName
    End if
    ActiveWorkbook.SaveAs s & sName
    end sub

    --
    Regards,
    Tom Ogilvy



    "Papa Waigo" wrote:

    >
    > I would like to be able to save a workbook using a macro, that will save
    > the file in a particular loaction e.g. C:\My Documents\Spreadsheet
    > Files\Example Spreadsheet.xls and have the directory created for those
    > users for whom it does not exist.
    >
    > I would also like the file to be named according to the contents of
    > cell c2 on a sheet named "list"
    >
    > Any help would be much appreciatted.
    >
    >
    > --
    > Papa Waigo
    > ------------------------------------------------------------------------
    > Papa Waigo's Profile: http://www.excelforum.com/member.php...o&userid=36074
    > View this thread: http://www.excelforum.com/showthread...hreadid=558861
    >
    >


  4. #4
    Registered User
    Join Date
    07-05-2006
    Posts
    7
    Thank you for your help here

    This code gives me a "subscript out of range" error

    any ideas?

  5. #5
    Tom Ogilvy
    Guest

    Re: Automatically Saving A Workbook

    That would be true if the activeworkbook doesn't have a worksheet with a name
    of LIST.

    --
    Regards,
    Tom Ogilvy


    "Papa Waigo" wrote:

    >
    > Thank you for your help here
    >
    > This code gives me a "subscript out of range" error
    >
    > any ideas?
    >
    >
    > --
    > Papa Waigo
    > ------------------------------------------------------------------------
    > Papa Waigo's Profile: http://www.excelforum.com/member.php...o&userid=36074
    > View this thread: http://www.excelforum.com/showthread...hreadid=558861
    >
    >


  6. #6
    Registered User
    Join Date
    07-05-2006
    Posts
    7
    Many thanks again, I can see what I've done wrong, this works perfectly.

    How could this be improved further so that a couple of checks take place before running the macro?

    Firstly if the filename already exists I would like a msgbox to appear stating "Name already exists", and the macro to stop running?

    Secondly I would like to check that cell b4 on a sheet named "Performance" is not empty before the macro runs, if it is empty then a msgbox should appears stating "please complete the WC date before continuing" and the macro should stop running
    Last edited by Papa Waigo; 07-07-2006 at 04:10 PM.

+ 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