Using If Then to check for a worksheet
I am creating an add-in for work. When the user opens the Add-in I
want to have code that checks to make sure a specific sheet exists in the workbook before the addin works. Something to the effect of If activeWorkbook contains "Sheet1" Then Copy "addin" else MsgBox "You have the wrong spreadsheet opened" Can someone help me work out the code? |
Using If Then to check for a worksheet
Dim wks as worksheet
set wks = nothing on error resume next set wks = activeworkbook.worksheets("doesitexist") on error goto 0 if wks is nothing then 'it ain't there 'do something else 'yep, it's there 'keep going end if ========= Although, I would think that this kind of thing would be better for each routine in your addin--instead of checking just the activeworkbook when the addin opens. stewdizzle wrote: I am creating an add-in for work. When the user opens the Add-in I want to have code that checks to make sure a specific sheet exists in the workbook before the addin works. Something to the effect of If activeWorkbook contains "Sheet1" Then Copy "addin" else MsgBox "You have the wrong spreadsheet opened" Can someone help me work out the code? -- Dave Peterson |
All times are GMT +1. The time now is 12:50 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com