Results 1 to 11 of 11

Thread: Delete Excel.Worksheet without stupid prompt?

  1. #1

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    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:
    1. Dim sheet As Excel.Worksheet
    2.     Set sheet = New Excel.Worksheet
    3.     sheet.Delete ' <-- This always prompts the user!! ARGH!

    Dave

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Delete Excel.Worksheet without stupid prompt?

    VB Code:
    1. Dim sheet As Excel.Worksheet
    2.     Set sheet = New Excel.Worksheet
    3.     Application.DisplayAlerts = False
    4.     sheet.Delete
    5.     Application.DisplayAlerts = True


  3. #3

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    A) How the heck did you know that?

    B) WOO-HOO!!!!!!!

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    VB Code:
    1. dim blnAlertStatus as boolean
    2.  
    3. '---- Turn off alerts
    4.     blnAlertStatus = Application.DisplayAlerts
    5.     Application.DisplayAlerts = false
    6.  
    7. '---- do processing
    8.  
    9. '---- Turn on alerts
    10.     Application.DisplayAlerts = blnDisplayAlerts
    There is another to freeze the sheet display, can't find it tho.


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    That would be:
    VB Code:
    1. Application.ScreenUpdating = False
    2. 'do stuff
    3. Application.ScreenUpdating = True

    It is a bit strange when you arent showing something else (and Excel is visible), as it looks like Excel has crashed. If your code crashes before you reset it then Excel can stay like it the next time it is opened too

  6. #6
    Lively Member
    Join Date
    Jul 2008
    Posts
    73

    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

  7. #7
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Delete Excel.Worksheet without stupid prompt?

    what is the error at that line?

  8. #8
    Lively Member
    Join Date
    Jul 2008
    Posts
    73

    Re: Delete Excel.Worksheet without stupid prompt?

    Quote Originally Posted by vbfbryce View Post
    what is the error at that line?
    error
    Public member 'Worksheets' on type 'Worksheet' not found

  9. #9
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Delete Excel.Worksheet without stupid prompt?

    Does worksheet "ABC" exist in that workbook?

  10. #10
    Lively Member
    Join Date
    Jul 2008
    Posts
    73

    Re: Delete Excel.Worksheet without stupid prompt?

    yes it does

  11. #11
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Delete Excel.Worksheet without stupid prompt?

    Can you post the whole code, including the variable definitions?

Posting Permissions

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



Click Here to Expand Forum to Full Width