Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default 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?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I copy a check box result from Worksheet A to Worksheet B? Javadan289 Excel Worksheet Functions 5 December 26th 06 07:25 PM
Check if worksheet is before another [email protected] Excel Discussion (Misc queries) 4 July 3rd 06 07:30 PM
check if worksheet is empty Lynn[_7_] Excel Programming 1 October 11th 05 03:41 PM
check if worksheet exists Judy Ward Excel Programming 2 August 10th 05 10:39 PM
How to check if a worksheet exists in worksheet collection Raghunandan Excel Programming 2 July 19th 04 06:55 AM


All times are GMT +1. The time now is 09:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"