Consulting

Results 1 to 3 of 3

Thread: How to get my macro to click a button in a dialog

  1. #1

    How to get my macro to click a button in a dialog

    I have a macro that creates 18 worksheets containing data following Sheet1 which remains blank. At the end of my macro I want to delete Sheet1. I added this to my macro:

    Sheets("Sheet2").Select
    ActiveWindow.SelectedSheets.delete

    Which works but requires the user to click the Delete button when the dialog button pop-ups.

    I'd like to have the macro click the delete button instead.

    Can anyone please help? TIA!!

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Sheets("Sheet2").Select
    application.displayalerts=false
    ActiveWindow.SelectedSheets.delete
    application.displayalerts=true
    but you realise this deletes sheet2, not sheet1.

    You could also try:
    application.displayalerts=false
    Sheets("Sheet1").delete
    application.displayalerts=true
    which will delete sheet1
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    p45cal,

    Thank you so much for your response. I appreciate it. Yes, the discrepancy, Sheet2 vs. Sheet1 was just in my quick example. I do intend to delete Sheet1 and my code is written as such -- just my example above was not.

    I've used your first suggestion and it's working wonderfully. Thank you so much! Big help!!

    Cheers!!

Posting Permissions

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