![]() |
How to check worksheets exist or not ?
Hi NickHK I just testing below coding. Very good result On Error GoTo 0 Thank a lot Moonhk NickHK wrote: Unless you have good reason, it is not advisable to run the whole routine with "On Error Resume Next" active. Make it active when you expect an error, deal with it and return to 'normal' error handling. As in Bob's example: On Error Resume Next Set loCIM =Application.Workbooks("apvomt_v5.xls").Worksheets ("Detail") On Error GoTo 0 If loCIM Is Nothing Then NickHK "moonhk" wrote in message oups.com... Thank, I am using below coding Public Sub Build_CIM() On Error Resume Next Dim loBook As Workbook Dim loSheet As Worksheet Dim loBookName As String Dim loSheetName As String Dim loCIM As Worksheet Dim cnt, cimCnt As Long cim.init loBookName = Application.ActiveWorkbook.Name loSheetName = Application.ActiveSheet.Name Application.StatusBar = "Processing..." & loSheetName MsgBox loSheetName Set loCIM = Application.Workbooks("apvomt_v5.xls").Worksheets( "Detail") If loCIM Is Nothing Then MsgBox "Workbook not opened apvomt_v5.xls" Exit Sub End If Set loSheet = Application.Workbooks(loBookName).Worksheets(loShe etName) '~~ Temp If loSheet Is Nothing Then MsgBox "Workbook not opened " & loBookName & " " & loSheetName Exit Sub End If option site.getConfig ("SH-451455") cnt = 3 cimCnt = 7 '~~MsgBox site.s1dnAddr & "CIM=" & cim.s2BatchAddr Do '~~ Setup Invoice Value loCIM.Range(cim.s2InvoiceAddr & cimCnt).Value = _ loSheet.Range(site.s1dnAddr & cnt).Value '~~ Update counter cimCnt = cimCnt + 1 cnt = cnt + 1 Loop While VBA.Trim(loSheet.Range(site.s1dnAddr & cnt)) < "" MsgBox cnt End Sub Bob Phillips wrote: On Error Resume Next SheetExists = CBool(Not Application.Workbooks("myWorkBook") _ .Worksheets("myWorksheet") Is Nothing) On Error GoTo 0 If SheetExists Then Set loWS = Application.Workbooks("myWorkBook").Worksheets("my Worksheet") -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "moonhk" wrote in message oups.com... How to check worksheets exist or not ? Dim loWS As Worksheet Set loWS = Application.Workbooks("myWorkBook").Worksheets("my Worksheet") |
All times are GMT +1. The time now is 02:43 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com