+ Reply to Thread
Results 1 to 17 of 17

How to save worksheet with userform control button

  1. #1
    Registered User
    Join Date
    03-13-2012
    Location
    perth,australia
    MS-Off Ver
    Excel 2007
    Posts
    25

    How to save worksheet with userform control button

    Hi All

    I've searched for hours, and sorry that I could not find anything that suits, or works in my case.

    I am trying to save a worksheet ("Blinds Quote") with the filename as the value in "C2", in a folder ("Customers") on the desktop, via a command button on a userform. If at all possible, I would also like the saveAsdialog box to appear with the filename and destination already populated, so that the user can check, or change these fields, if needs be. All he has to do then is press 'save'. A returning message saying that the save has been successful would be good.

    I am using Win7 with excel 2007.

    Thanks everyone for your time and efforts to keep us dummies happy.

    Fremarco
    Last edited by fremarco; 07-04-2012 at 07:50 AM.

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: How to save worksheet with userform control button

    Hi,

    1 - Place an active commandbutton on your sheet.

    2 - Insert this code into the sheet module (You open the sheet module by right clicking the sheet tab and press view code)

    Please Login or Register  to view this content.
    3 - Set the save as file name in same sheet in range "C2"

    4 - press the button
    Please take time to read the forum rules

  3. #3
    Registered User
    Join Date
    03-13-2012
    Location
    perth,australia
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: How to save worksheet with userform control button

    Please Login or Register  to view this content.

    Hi Steffen.

    Thank you for responding so quickly. I have done what you said but I am getting a 'compile error' when I push the button. It highlights the 'PtrSafe' part of the code, on the first line. I will keep trying, to make sure it's not something I've missed.

  4. #4
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: How to save worksheet with userform control button

    Ok, then remove Ptrsafe, Ptrsafe is only for 64-bit version of excel

  5. #5
    Registered User
    Join Date
    03-13-2012
    Location
    perth,australia
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: How to save worksheet with userform control button

    Hi Steffen

    I'm still not having any luck, but Thank You for trying for me.

  6. #6
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: How to save worksheet with userform control button

    Still the same line?

  7. #7
    Registered User
    Join Date
    03-13-2012
    Location
    perth,australia
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: How to save worksheet with userform control button

    Yes, Steffen. I deleted that line but the error now points to the next line 'SetCurrentDirectory'

  8. #8
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: How to save worksheet with userform control button

    Try uploading a sample workbook and ill give it a go.

  9. #9
    Registered User
    Join Date
    03-13-2012
    Location
    perth,australia
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: How to save worksheet with userform control button

    Thanks Steffen. Here is a small sample. Is this enough?
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: How to save worksheet with userform control button

    Try this, just press the button.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    03-13-2012
    Location
    perth,australia
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: How to save worksheet with userform control button

    Thanks Steffen as we seem to be getting somewhere, though it is not actually saving it to the 'customer' folder on the desktop, or anywhere else that I can see. I pressed 'Save item' and the dialog box appeared with the value of C2 as the file name, which is great, but when I press 'save', no save happened. I did a search for the filename but nothing was found. Thanks for giving it a go.

  12. #12
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: How to save worksheet with userform control button

    Sorry, missing a bit

    This works.

    Please Login or Register  to view this content.
    Last edited by Steffen Thomsen; 07-04-2012 at 02:03 AM. Reason: Added code

  13. #13
    Registered User
    Join Date
    03-13-2012
    Location
    perth,australia
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: How to save worksheet with userform control button

    Thanks Again. Still not working though. It must be something at my end, which I'm looking at now. I don't think my system likes the file format, so I'm investigating. Will post again if I make any headway. Thanks very much Steffen.

  14. #14
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: How to save worksheet with userform control button

    Try and debug, maby the folder path doesnt exist, this could be that your user folder is named fre.macro and getUserName returns fremacro,
    Just a suggestion. Have you tried setting a debug point and controlling that the variable holds the expected value?

  15. #15
    Registered User
    Join Date
    03-13-2012
    Location
    perth,australia
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: How to save worksheet with userform control button

    Thank you Steffen. I've managed to get your code working. The problem was with the Ptrsafe, which I removed as you suggested. I didn't notice that I needed to manually remove a space from between the 'declare' and 'function'. All I need to do now is figure out how to get it to save in my 'customers' folder.

    Thanks again for your time and your patience with me.

  16. #16
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: How to save worksheet with userform control button

    This you can do by editing this line

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    Glad i could help

  17. #17
    Registered User
    Join Date
    03-13-2012
    Location
    perth,australia
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: How to save worksheet with userform control button

    Thanks Steffen. I actually managed that one myself. There's hope for me yet. All the best to you

+ 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