Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to check from VBA if sheet exists?
How to check from VBA if sheet named "JohnDoe" exists in workbook?
Sub del_sheet() if exist(sheets("JohnDoe")) then application.displayalerts = false sheets("JohnDoe").delete application.displayalerts = true end if With what code I have to put instead of "exist(sheets("JohnDoe"))" Regards, Alen |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to check from VBA if sheet exists?
Here's the code:
Public Sub VérifierFeuille(ByVal strValeur As String) Dim wSheet As Worksheet On Error Resume Next Set wSheet = ActiveWorkbook.Sheets(strValeur) If wSheet Is Nothing Then MsgBox "The sheet" + strValeur + " is not present, the application will be stop.", vbCritical + vbOKOnly, "Error" End Else Set wSheet = Nothing End If End Sub "Alen" a écrit dans le message de news: ... How to check from VBA if sheet named "JohnDoe" exists in workbook? Sub del_sheet() if exist(sheets("JohnDoe")) then application.displayalerts = false sheets("JohnDoe").delete application.displayalerts = true end if With what code I have to put instead of "exist(sheets("JohnDoe"))" Regards, Alen |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to check from VBA if sheet exists?
Chip Pearson posted this function:
Function WorksheetExists(SheetName As Variant, _ Optional WhichBook As Workbook) As Boolean 'from Chip Pearson Dim WB As Workbook Set WB = IIf(WhichBook Is Nothing, ThisWorkbook, WhichBook) On Error Resume Next WorksheetExists = CBool(Len(WB.Worksheets(SheetName).Name) 0) End Function 'and you can use it like: .... if worksheetexists("myname",activeworkbook) then application.displayalerts = false worksheets("Myname").delete application.displayalerts = true end if ============ But if I'm deleting, I don't ca application.displayalerts = false on error resume next sheets("JohnDoe").delete on error goto 0 application.displayalerts = true If it's not there, just ignore the error. Alen wrote: How to check from VBA if sheet named "JohnDoe" exists in workbook? Sub del_sheet() if exist(sheets("JohnDoe")) then application.displayalerts = false sheets("JohnDoe").delete application.displayalerts = true end if With what code I have to put instead of "exist(sheets("JohnDoe"))" Regards, Alen -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to check to see if a sheet with a particular name exists? | Excel Worksheet Functions | |||
check if sheet exists | Excel Discussion (Misc queries) | |||
check to see if sheet exists | Excel Programming | |||
Check to see if sheet exists | Excel Programming | |||
check if sheet exists | Excel Programming |