Closed Thread
Results 1 to 22 of 22

Saving in wrong location

Hybrid View

  1. #1
    Registered User
    Join Date
    09-22-2006
    Posts
    39

    Saving in wrong location

    Hi

    I have the following code which saves my worksheet with a name extracted from particular cells:

    Public Sub SaveAsMaximoWO()
    ThisFile = Range("AC5").Value
    ThisFile2 = Range("E3").Value
    saveName = ThisFile & " - " & ThisFile2
    ActiveWorkbook.SaveAs Filename:=saveName

    End Sub

    This (for reasons I don't understand) saves the file to My Documents by default.

    What I would like it to do is save to another folder within my documents as default. How can I do this?

    Any help greatly appreciated

    Many Thanks

    Chris

  2. #2
    Forum Contributor funkymonkUK's Avatar
    Join Date
    01-07-2005
    Location
    London, England
    Posts
    500
    The reason being is that you have not specificied the folder location thus it is storing it in your default location i.e My documents.

    What you need to do is specify the full address like "c:/My Documents/Testing folder/" & Thisfile etc.

    Try this

    Sub SaveAsMaximoWO()
    dim ThisFile as string
    dim thisfile2 as string
    Dim WorkPath as string

    ThisFile = Range("AC5").Value '
    ThisFile2 = Range("E3").Value ' not sure if it already has the .xls extension so will add it into the string
    WorkPath = thisworkbook.path & "/Save Folder"

    saveName = WorkPath & '/' & ThisFile " - " & ThisFile2 & ".xls"
    ActiveWorkbook.SaveAs Filename:=saveName

    End Sub

    so in this case what should happen is that say the activeworkbook is in My documents then it would save it in My documents under the subfolder called "Save Folder". Just make sure that the subfolder exists else it will crash.

  3. #3
    Registered User
    Join Date
    09-22-2006
    Posts
    39
    Thanks ever so much for your help.

    I have implemented the code you suggest and it says there is a syntax error on the following line:

    saveName = WorkPath & '/' & ThisFile & " - " & ThisFile2 & ".xls"

    I am not sure what this means? I have checked that the workPath folder exists in my documents so not sure why it isn't working.

    As an aside, is it always necessary to declare varialbes in macros as you have done or is it just good practice?

    Chris

  4. #4
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    There was just an "&" missed out change the line for this below:
    saveName = WorkPath & "/'" & ThisFile & " - " & thisfile2 & ".xls"
    Regards,
    Simon

    P.S dont for get to Dim saveName
    Last edited by Simon Lloyd; 09-26-2006 at 05:04 AM.

  5. #5
    Forum Contributor funkymonkUK's Avatar
    Join Date
    01-07-2005
    Location
    London, England
    Posts
    500
    thanks for for replying on my behalf simon.

  6. #6
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    No problem im no expert so had to try the code see why it didnt work and process of elimination.........just beat you to the reply thats all.........i surprised myself that i got it!

    Regards,
    Simon

Closed 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