Closed Thread
Results 1 to 22 of 22

Saving in wrong location

  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:
    Please Login or Register  to view this content.
    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

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

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

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

  10. #10
    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
    Sorry FunkyMonk didn't mean to tread on your toes!

    Simon

  11. #11
    Forum Contributor funkymonkUK's Avatar
    Join Date
    01-07-2005
    Location
    London, England
    Posts
    500
    run this and see what it is returning sometimes you maybe returning a double / by mistake.

    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"
    msgbox workpath
    saveName = WorkPath & "/'" & ThisFile & " - " & Thisfile2 & ".xls"
    msgbox savename
    ActiveWorkbook.SaveAs Filename:=saveName

    End Sub

  12. #12
    Forum Contributor funkymonkUK's Avatar
    Join Date
    01-07-2005
    Location
    London, England
    Posts
    500

    Talking

    Quote Originally Posted by Simon Lloyd
    Sorry FunkyMonk didn't mean to tread on your toes!

    Simon
    its alright I like a bit of competion

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

    Smile

    Wahoo, right, it works. Thanks.

    I think the technical term for me in this instance is "turdface".

    Basically, Simon got my rather slow brain ticking. The folder I wanted to save to was not on the same path as the file I was saving from, so it was trying to save to some very odd place indeed!

    Therefore I got rid of the thisActiveWorkbook.path and just put in the path (minus the drive name as other computers may have different drive names) and it works!

    Again, I really appreciate the help. I'm a philosopy graduate, I should be nowhere near this! But becuase I don't sweat with fear when I switch my computer on (and my boss won't buy software) then he thinks it would be a good idea to make me into a programmer. Unfortuntely, it's you blokes who get the fall-out. Thanks again, I'll be back!

  14. #14
    Forum Contributor funkymonkUK's Avatar
    Join Date
    01-07-2005
    Location
    London, England
    Posts
    500
    well I have no higher education, my boss/IT department wont upgrade our systems (windows NT/Office 97 with some machine including mine which have been upgraded to excel 2000 not even the complete office package).

    VBA programmers can get paid loads to customerise Excel so maybe get your boss to send you on some courses and then leave him but I work in the public sector but looking for a better paid job. As the skills I have dont match my salary.

    SO glad we could be of some assistance

  15. #15
    Forum Contributor funkymonkUK's Avatar
    Join Date
    01-07-2005
    Location
    London, England
    Posts
    500
    Quote Originally Posted by Simon Lloyd
    Sorry FunkyMonk didn't mean to tread on your toes!

    Simon
    Seems like you not only tread on my toes you F*&king jumped on them on this occasion.

  16. #16
    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
    Me neither and i dont have the skills to match my job! (hehe) maybe if we slammed our heads together hard enough we could amount to something!

    Simon

  17. #17
    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
    Errr........... i have a pair of steel toe capped boots if you like, size 9, they may afford you some protection from my clumsiness!

    regards,
    Simon

  18. #18
    Forum Contributor funkymonkUK's Avatar
    Join Date
    01-07-2005
    Location
    London, England
    Posts
    500
    Quote Originally Posted by Simon Lloyd
    Me neither and i dont have the skills to match my job! (hehe) maybe if we slammed our heads together hard enough we could amount to something!

    Simon
    hehehehe - banging heads together sounds a bit naff.

  19. #19
    Registered User
    Join Date
    09-22-2006
    Posts
    39
    I think me banging my head may have something to do with the fact that programming is way beyond me! So I will have to decline....

  20. #20
    Registered User
    Join Date
    06-22-2005
    Location
    Washington, USA
    MS-Off Ver
    Office 365
    Posts
    40
    I came across this thread through a search. It has been helpful so far.

    What if I don't want to specify the filename and leave it up to the user. I want to point it to a specific folder, but the user can name the file as they see fit.

    thanks.

    -joel

  21. #21
    Registered User
    Join Date
    06-22-2005
    Location
    Washington, USA
    MS-Off Ver
    Office 365
    Posts
    40
    nevermind, I found the answer, but it wasn't clear to me until I started playing around with it.

    I used:

    Application.GetSaveAsFilename "enter/the/path/here"

    Hope this helps someone.

    -joel

  22. #22
    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
    Joel, glad you found the forum useful and thanks for your comments!
    Not all forums are the same - seek and you shall find

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