deleting worksheet in excel workbook 
Author Message
 deleting worksheet in excel workbook

Hi

i am using following code to delete a worksheet in excel workbook

Set appExcel = CreateObject("Excel.Application")
filePath = "C:\temp\testBook.xls"
set bookExcel = appExcel.Workbooks.Open(filePath, ,false)
bookExcel.Sheets(2).Delete

Problem:
It pops up a Msg box
[
"Selected sheet will be permanently deleted"
Click ok to delete]

How can i avoid or by pass this msgbox?

while adding worksheet it does not asks anything.it  simply adds
worksheet

thanks
Sanjeev

--
Posted via http://www.*-*-*.com/



Sun, 25 Sep 2005 08:50:40 GMT  
 deleting worksheet in excel workbook
Sanjeev

Try this

appExcel.DisplayAlerts = False
bookExcel.Sheets(2).Delete
appExcel.DisplayAlerts = True

Setting DisplayAlerts to False will force Excel to accept the default button
on most dialog boxes.  The default for deleting a sheet is OK, so that
should work good for your situation.

--
{*filter*} Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.


Quote:

> Hi

> i am using following code to delete a worksheet in excel workbook

> Set appExcel = CreateObject("Excel.Application")
> filePath = "C:\temp\testBook.xls"
> set bookExcel = appExcel.Workbooks.Open(filePath, ,false)
> bookExcel.Sheets(2).Delete

> Problem:
> It pops up a Msg box
> [
> "Selected sheet will be permanently deleted"
> Click ok to delete]

> How can i avoid or by pass this msgbox?

> while adding worksheet it does not asks anything.it  simply adds
> worksheet

> thanks
> Sanjeev

> --
> Posted via http://www.*-*-*.com/



Sun, 25 Sep 2005 22:49:24 GMT  
 deleting worksheet in excel workbook

Hi{*filter*}

Thanks a lot.
It worked, and removed a very big hurdle of my project where I have to
delete worksheets from an excel template based on users input.

thanks again
if you can suggest any website which provides office automation details
or any book, it will be a great help

sanjeev

--
Posted via http://www.*-*-*.com/



Mon, 26 Sep 2005 00:19:57 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How can I open Excel workbook without using Excel.Worksheet

2. Word/Excel Insert Single Worksheet from Workbook

3. function to see if an Excel worksheet name exitsts in a workbook

4. processing excel rows - separate workbooks/worksheets

5. Excel - Use the current workbook and worksheet

6. detect the worksheet-names in an EXCEL 5.0 workbook

7. Excel Workbook vs. Worksheet

8. wsh/vba for excel automation: moving worksheets beetween workbooks

9. Accessing a worksheet in an Excel workbook

10. Save a Worksheet in Excel to a Master Workbook

11. Unable to delete and Excel Workbook from VBA

12. VBScript Item.Delete?, run Excel Workbook from public folder

 

 
Powered by phpBB® Forum Software