Consulting

Results 1 to 3 of 3

Thread: Close messages

  1. #1
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location

    Close messages

    I close a worbook with this code:

    [VBA]Sub CloseSheet()

    Windows("Avalon Balanced Accounts.xls").Activate
    ActiveWindow.Close
    End Sub[/VBA]

    After copying data on a workbook and pasting it into a new sheet, I want to close the original worbook in which i copied data from.
    After I run this code to close the original workbook, I get two messages about closing the book. The first one asks if i want to save changes, and I want to say "No.". The second message pops up after that and says there is a large amount of information copied, and do I want to save it to the clipboard. I also want to say "No" here. How do I incorporate that into my code to say no to both messages?

  2. #2
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    Try this:
    [vba]
    Sub CloseWorkbook()
    ThisWorkbook.Saved = True
    Application.CutCopyMode = False
    ThisWorkbook.Close
    End Sub[/vba]

    Of course you could change ThisWorkbook with ActiveWorkbook or set a variable as a workbook and close that instead...

  3. #3
    Hi,

    This should do it. Change "Your Workbook Name" to match your own workbook.

    [VBA]Application.DisplayAlerts = False

    Windows("Your Workbook Name.xls").Close

    Application.DisplayAlerts = True
    [/VBA]
    Feedback is the best way for me to learn


    Follow the Armies

Posting Permissions

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