Results 1 to 4 of 4

Thread: VBA Save As Function

  1. #1

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    got there in the end

    Just got home David, try this under the button_click() event :

    Code:
    With CommonDialog1
        .ShowSave
        .Filter = "*.xls"
        .DialogTitle = "save as example"
    End With
    getfiletosave = CommonDialog1.FileName
    Excel.Workbooks(0).Item.SaveAs getfiletosave
    hope this helps.
    Alex

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  2. #2

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    valuable lesson

    For your one, try
    Code:
    ThisWorkbook.SaveAs CommonDialog1.FileName
    instead of the last line.

    checked 3 ms sites for the filter bit, and just realised the above is c**p, maybe someone else can shed some light on this part, but the above will save your files.


    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    263
    This is the code I have. This works too.

    Code:
    Private Sub CommandButton1_Click()
    CommondDialog1.ShowSave
    ActiveWorkbook.SaveAs FileName:=CommonDialog1.FileName
    End Sub
    
    Private Sub UserForm_Intitialize()
    CommonDialog1.Filter = "Excel Spreadsheet(*.xls)|*.xls|"
    CommonDialog1.FilterIndex = 1
    End Sub
    This works. Now, when the Save As dialog comes up, and I hit cancel, it comes up with a debug error message. Why is that?
    Thanks Alot,

    David Gottlieb
    CIW Certified Internet Webmaster
    Web Developer/Designer

  4. #4

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Talking because it's made by microsoft ...

    You have a line :

    Code:
    CommonDialog1.CancelError = False
    which you can add in your CommandButton1_Click() part, or you an do a..

    Code:
    If CommonDialog1.Cancel = True Then
       'code to cancel here
    End if
    statement. Note I have tried this before posting this time!

    Alex Read


    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

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