Consulting

Results 1 to 4 of 4

Thread: Solved: Answer No to Alert When DisplayAlerts = False

  1. #1
    VBAX Regular
    Joined
    Oct 2005
    Location
    Westhoughton, England
    Posts
    47
    Location

    Solved: Answer No to Alert When DisplayAlerts = False

    Hi,

    I have a routine that opens a workbook with a large amount of data on a worksheet, copies the data, pastes it into a worksheet in another workbook and then closes the original workbook. See the code below:

    [vba]
    Workbooks.Open ("path for original workbook")
    Workbooks("original workbook").Activate
    ActiveWorkbook.Worksheets(1).Cells.Copy
    Workbooks("destination workbook").Activate
    ActiveWorkbook.Worksheets("destination sheet").Cells.Select
    ActiveSheet.Paste
    Application.DisplayAlerts = False
    Workbooks("original workbook").Close
    Application.DisplayAlerts = True
    [/vba]

    Normally, when the original workbook is closed the alert regarding saving the Clipboard data appears - I have used "DisplayAlerts = False" to suppress this but of course DisplayAlerts answers each alert with the default option which in this case is "Yes", therefore saving the data to the clipboard. But there is a lot of data so this takes up a lot of memory.

    So my question is: is there a way to suppress alerts but answer "No" to this specific alert?

    Thanks,
    Neil Belch
    Senior Software Technician
    CDL Production Services Ltd

    The views opinions and judgements expressed in this message are solely those of the author.
    The message contents have not been reviewed or approved by CDL.

  2. #2
    VBAX Regular
    Joined
    Mar 2006
    Posts
    44
    Location

    Simple Fix

    This should do the trick:
    [VBA]Workbooks.Open ("path for original workbook")
    Workbooks("original workbook").Activate
    ActiveWorkbook.Worksheets(1).Cells.Copy
    Workbooks("destination workbook").Activate
    ActiveWorkbook.Worksheets("destination sheet").Cells.Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Application.DisplayAlerts = False
    Workbooks("original workbook").Close
    Application.DisplayAlerts = True [/VBA]
    This clears the clipboard.
    Sean.

  3. #3
    VBAX Regular
    Joined
    Oct 2005
    Location
    Westhoughton, England
    Posts
    47
    Location
    Works a treat, I don't even need the DisplayAlerts lines now.

    Cheers Sean.
    Neil Belch
    Senior Software Technician
    CDL Production Services Ltd

    The views opinions and judgements expressed in this message are solely those of the author.
    The message contents have not been reviewed or approved by CDL.

  4. #4
    VBAX Regular
    Joined
    Mar 2006
    Posts
    44
    Location
    No worries.
    Sean.

Posting Permissions

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