+ Reply to Thread
Results 1 to 17 of 17

Using VBA to automatically save the file name from the worksheet cells.

  1. #1
    Registered User
    Join Date
    02-14-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    97

    Question Using VBA to automatically save the file name from the worksheet cells.

    Hi Folks,

    I am after a way of saving the current worksheet (sheet2 Service Report) to a new book and using cells C16 (Customer Name) and F10 (Date) to automatically save as the file name. I also need the folder path to be "C:\Documents and Settings\carl.walker\My Documents\Forms\".

    I have had a crack at it with the code below, although I can get both bits to work well seperatly, I dont understand enough for me to combine them for what I want them to do.

    If anyone could help me with this it would be much appreciated.....
    Thanks in advance :o)
    Carl


    FIRST LINE OF CODE:

    Please Login or Register  to view this content.
    SECOND LINE OF CODE:

    Please Login or Register  to view this content.
    Last edited by vlady; 11-12-2012 at 09:28 PM. Reason: code tags

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Using VBA to automatically save the file name from the worksheet cells.

    FIRST LINE OF CODE:

    Please Login or Register  to view this content.
    SECOND LINE OF CODE:

    I can not help you, I don't know the content of cells B16 F10
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    02-14-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    97

    Post Re: Using VBA to automatically save the file name from the worksheet cells.

    Hi Patel,

    I have uploaded the workbook in question for you to veiw, Idealy I would like both pieces of code merged so that the info taken from cells B16 and F10 become the name of the saved file.

    Many Thanks
    Carl :o)
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Using VBA to automatically save the file name from the worksheet cells.

    you attached an empty workbook, then
    I can not help you, I don't know the content of cells B16 F10

  5. #5
    Registered User
    Join Date
    02-14-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: Using VBA to automatically save the file name from the worksheet cells.

    Hi,

    Sorry about that, here's the original.

    Regards
    Carl
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Using VBA to automatically save the file name from the worksheet cells.

    SECOND LINE OF CODE:
    Please Login or Register  to view this content.
    1) A folder name can not have chars like / \ : * |
    2) There is nothing in column F

  7. #7
    Registered User
    Join Date
    02-14-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    97

    Post Re: Using VBA to automatically save the file name from the worksheet cells.

    Hi Patel,

    Thanks for that, but what I need is something like the below code to work if possible.
    The user form puts the date in F10 and underscore seems to save ok as a filename.
    If you know a way of getting the following to work that would be great.


    Sub SaveMyWorkbook()

    Worksheets(Array("ServiceReport")).Copy
    With ActiveWorkbook &_


    Dim strPath As String
    Dim strFolderPath As String
    strFolderPath = "C:\Documents and Settings\carl.walker\My Documents\Forms\"
    strPath = strFolderPath & _
    Sheet2.Range("b16").Value & " " & _
    Sheet2.Range("f10").Value & ""


    End Sub


    Kind Regards
    Carl

  8. #8
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Using VBA to automatically save the file name from the worksheet cells.

    Carl, if you want solve you have to attach a correct file, as I suggested, no file no answer from me.

  9. #9
    Registered User
    Join Date
    02-14-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: Using VBA to automatically save the file name from the worksheet cells.

    Hi Patel,

    I'm a little confused with what you have said so I have attached another workbook, the sheet I want the code to work on is sheet 2(Service Report).

    Hope this helps and sorry for any confusion.

    Regards
    Carl
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Using VBA to automatically save the file name from the worksheet cells.

    I repeat a second time
    1) A folder name can not have chars like / \ : * |
    In column B descriptions start with R/c, then you can not save with this name because ther is the char /

  11. #11
    Registered User
    Join Date
    02-14-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: Using VBA to automatically save the file name from the worksheet cells.

    Ah I see the confusion now!

    The referenced cells B16 and F10 are on sheet 2 (Service Report) not sheet 1 (Parts List). I only want to be able to save sheet 2 (Service Report) using its cells B16 and F10 to save as the filename.

    Sorry for the confusion I know I asked for the current sheet to be saved when I should of asked for Sheet 2 to be saved instead.

    Kind Regards
    Carl

  12. #12
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Using VBA to automatically save the file name from the worksheet cells.

    The referenced cells B16 and F10 on sheet 2 (Service Report) are empty

  13. #13
    Registered User
    Join Date
    02-14-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: Using VBA to automatically save the file name from the worksheet cells.

    Hi Patel,

    Cells B16 and F10 get populated by the userform attached to that sheet. B16 (Account Details) will be text and numbers and F10 (Date) is set in the following format dd_mm_yy.

    Hope this helps

    Regards
    Carl

  14. #14
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Using VBA to automatically save the file name from the worksheet cells.

    Again
    Carl, if you want solve you have to attach a correct file, as I suggested, no file no answer from me.

  15. #15
    Registered User
    Join Date
    02-14-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: Using VBA to automatically save the file name from the worksheet cells.

    As requested.

    Regards Carl
    Attached Files Attached Files

  16. #16
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Using VBA to automatically save the file name from the worksheet cells.

    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    02-14-2012
    Location
    Newcastle, England
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: Using VBA to automatically save the file name from the worksheet cells.

    Patel,

    Thank you very much, I know I haven't been the easiest novice to communicate with!

    I settled with sub (savemyworkbook) as you have it working perfectly.


    Again Many Thanks
    Carl

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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