Results 1 to 8 of 8

Thread: Save As Function in VBA

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    263

    Question

    I have a form in excel. I have created a button that will save the file. What is supposed to happen is that the form is supposed to be saved as the "control number" which is in cell A3. How can I save a file that will reference a cell for the file name???

    Thanks Alot,

    David Gottlieb
    CIW Certified Internet Webmaster
    Web Developer/Designer

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Code:
    Dim sFileName As String
    sFileName = ActiveSheet.Range("C3").Value
    ActiveWorkbook.SaveAs sFileName
    Good luck!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    263
    for some reason that is not working. What's wrong?
    Thanks Alot,

    David Gottlieb
    CIW Certified Internet Webmaster
    Web Developer/Designer

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    This code should work:
    Code:
    Dim sFileName As String
    sFileName = ActiveSheet.Range("A3").Value
    ActiveWorkbook.SaveAs sFileName

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    263
    Ok. I got it to work. It was a formula but I copied and pasted values. One problem. I am using the =NOW() formula for the control number in the Number format. I have it so it will display up to only 5 decimal places. However, when it saves the form, it saves it with like 10 decimal places. How can I keep that from happening? Also, when I used that code it doesn't come up with a dialog box for Save As. It just saves it. Help

    Thanks Alot,

    David Gottlieb
    CIW Certified Internet Webmaster
    Web Developer/Designer

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    263
    That code works but, I need for the Save As dialog box to come up so the user can specify what folder to save it in. How do I do that?
    Thanks Alot,

    David Gottlieb
    CIW Certified Internet Webmaster
    Web Developer/Designer

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Sorry you can't have it both ways.
    Either you pass a file name to the SaveAs method, and in that Excel saves the file without prompting, or you don't pass a file name to the method in which case Excel throghs up the Save As dialog so the user can choose a path and a name for the file.

    Of course you could call SaveAs without the file name argument let the user set the path and the name and then you rename the file afterwards.

    Or call up the "Browse for Folder" dialog so the user can only choose a path and not a name for the file.
    See the tips section here at VB-World on how to call this dialog.

    Best regards

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    263
    I tried the Call SaveAs and it came up with an error. "Sub or Function not defined." what am I doing wrong?
    Thanks Alot,

    David Gottlieb
    CIW Certified Internet Webmaster
    Web Developer/Designer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width