Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Apr 2001
    Location
    Toronto, Ontario, Canada
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Close workbook w/out saving changes. (xl97)

    I have an Excel report which is distributed internally on a network via e-mail. There is a line of code in the BeforeClose event of the workbook which forces the close of the workbook without saving changes...
    Workbooks("Filename.xls").Close SaveChanges:=False
    This works fine in most cases, but occasionally when the file is opened from the e-mail attachment (i.e. not having been saved locally), it is temporarily assigned a different filename (i.e. "Filename1.xls") and therefore the script fails when the workbook is closed.

    How can I change this line of script so that variable filenames will not affect the code.

    Many Thanks,

    Rob.

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

    Re: Close workbook w/out saving changes. (xl97)

    If the macro code is in the workbook, then:

    <pre> ThisWorkbook.Close SaveChanges := False
    </pre>


    If the workbook is the active workbook, then:

    <pre> ActiveWorkbook.Close SaveChanges := False
    </pre>

    Legare Coleman

  3. #3
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Close workbook w/out saving changes. (xl97)

    The following line of code should do the job :<pre>ActiveWorkbook.Close SaveChanges:=False</pre>

    Andrew C

  4. #4
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: Close workbook w/out saving changes. (xl97)

    <P ID="edit" class=small>Edited by WebGenii on 20-Sep-01 16:12.</P>Try this line instead
    ActiveWorkbook.Close savechanges:=False

    --------
    Oops didn't realize I'd be the third one in!
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

Posting Permissions

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