Delete Excel.Worksheet without stupid prompt?
Hi,
Lookin to delete sheets in the Excel.Workbook without the user being prompted fro EVERY sheet I delete in code.
ie..
VB Code:
Dim sheet As Excel.Worksheet
Set sheet = New Excel.Worksheet
sheet.Delete ' <-- This always prompts the user!! ARGH!
Dave
Re: Delete Excel.Worksheet without stupid prompt?
VB Code:
Dim sheet As Excel.Worksheet
Set sheet = New Excel.Worksheet
Application.DisplayAlerts = False
sheet.Delete
Application.DisplayAlerts = True
:)
Re: Delete Excel.Worksheet without stupid prompt?
i am having total of 4 sheets of which sheet 1 & sheet 4 r compulsory
i am using datatable to fill the sheet with data
if dt1.rows.count<>0
-- write data to excel cells
else
oWB1.Application.DisplayAlerts = False
oWB1.Sheets("ABC").Delete
oWB1.Application.DisplayAlerts = True
end if
if dt2.rows.count<>0
-- write data to excel cells
else
oWB1.Application.DisplayAlerts = False
oWB1.Sheets("XYZ").Delete
oWB1.Application.DisplayAlerts = True
end if
i get error when it goes to else part of dt1 ie on the line
oWB1.Sheets("ABC").Delete
but if dt2 count is 0 the else part gets executed sucessfully ie the sheet 3 gets deleted
Re: Delete Excel.Worksheet without stupid prompt?
what is the error at that line?
Re: Delete Excel.Worksheet without stupid prompt?
Quote:
Originally Posted by
vbfbryce
what is the error at that line?
error
Public member 'Worksheets' on type 'Worksheet' not found
Re: Delete Excel.Worksheet without stupid prompt?
Does worksheet "ABC" exist in that workbook?
Re: Delete Excel.Worksheet without stupid prompt?
Re: Delete Excel.Worksheet without stupid prompt?
Can you post the whole code, including the variable definitions?