Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    saveas error (XL 2000 sr1)

    I have a strange problem which has me beat. I've attached a sample file to demonstrate.
    the file runs a macro which simply uses saveas to save the file to a new name, you type a name in a box and it is used to name the file.
    this works fine during the run, but the problem appears when you attempt to close the file after the macro has run. If you close the application (exit XL) all is fine but if you close only the workbook XL crashes.
    Can anyone give me some insight into what might be causing the problem.

    Thanks, Glenn
    Attached Files Attached Files

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: saveas error (XL 2000 sr1)

    The same thing happens here. I found what is causing it, but I don't know why. My only guess is that it is a bug in XL. Anyhow, if you remove B1 as a control source for the textbox on the form, and replace the code in the Start button with this below, it should do the same thing and not cause XL to crash. I also made a change to not save the workbook if the user clicks DONE with nothing in the textbox, and another check to not add the .xls file extension if it is already there.

    <pre>Private Sub CommandButton2_Click()
    UserForm1.TextBox1.Value = Worksheets("sales copy").Range("B1").Value
    UserForm1.Show
    '
    customer$ = UserForm1.TextBox1.Value
    If customer$ = "" Then Exit Sub
    If Right$(customer$, 4) <> ".xls" Then
    customer$ = customer$ & ".xls"
    End If
    Worksheets("sales copy").Range("B1").Value = customer$
    ActiveWorkbook.SaveAs Filename:=customer$, ConflictResolution:=xlLocalSessionChanges
    Range("b5").Select
    End Sub
    </pre>

    Legare Coleman

  3. #3
    New Lounger
    Join Date
    Mar 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: saveas error (XL 2000 sr1)

    Many thanks,
    problem solved, it never occurred to me that the control sources could be causing the problem, they seem unrelated.
    Thanks as well for your suggestions to improve the code, though the one about an empty name was already in the original macro. I created the example to demo the problem and therefore removed the much extraneous code.

    Regards, Glenn

Posting Permissions

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