PDA

View Full Version : [SOLVED] How to get my macro to click a button in a dialog



justjulier
05-03-2015, 02:53 PM
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!!

p45cal
05-03-2015, 04:43 PM
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=truewhich will delete sheet1

justjulier
05-05-2015, 02:06 PM
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!!