Closed Thread
Results 1 to 22 of 22

Saving in wrong location

Hybrid View

  1. #1
    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.

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

  3. #3
    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.

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

  5. #5
    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

  6. #6
    Registered User
    Join Date
    09-22-2006
    Posts
    39
    Hi again!

    Really sorry to ask again, as I am sure I am missing something really stupid here (again). Here is the code:

    Sub SaveAsMaximoWO()
    Dim ThisFile As String
    Dim Thisfile2 As String
    Dim WorkPath As String
    Dim saveName 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 & "/Gas Sheets"

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

    End Sub

    Yet when it runs it is coming up with and error and highlighting the last line when I go into debugging.

    My uselessness in this is quite embarassing....

  7. #7
    Forum Contributor funkymonkUK's Avatar
    Join Date
    01-07-2005
    Location
    London, England
    Posts
    500
    do you mind me asking what value is the thisfile and thisfile2? i know you cant use certain symbols when saving a workbook.

  8. #8
    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
    all i can assume is that you dont have a folder called Gas sheets in the same path as the excel workbook you opened because the code worked for me if i created the folder gas sheets

    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