Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
jkt jkt is offline
external usenet poster
 
Posts: 3
Default How can I look for a sheet in a wkbk and run a macro if not there

I need to look for a sheet name within a workbook and run a macro if the
sheet name does not exist. any suggestions?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 324
Default How can I look for a sheet in a wkbk and run a macro if not there

I have used a form of the following:

On error goto macrorun
Sheets("Sheetname").Activate

macrorun:
call your macro
--
Best wishes,

Jim


"jkt" wrote:

I need to look for a sheet name within a workbook and run a macro if the
sheet name does not exist. any suggestions?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 324
Default How can I look for a sheet in a wkbk and run a macro if not there

I forgot to mention that if there are worksheets that are hidden, you would
need to add:
On error resume next
Sheets("sheetname").visible=true
on error goto 0

Then the rest from the previous response.
--
Best wishes,

Jim


"jkt" wrote:

I need to look for a sheet name within a workbook and run a macro if the
sheet name does not exist. any suggestions?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default How can I look for a sheet in a wkbk and run a macro if not th

Using this code may cause you a problem as it moves from normal execution to
exectuion within an errorhandler (there is no resume statement to exit the
error handler). This means that if any other error are generated they can not
be handled. You are better off with code like this...

sub do whatever()
if sheetexists("Sheet1") = false then
call MyMacro
end if
exit sub

Public Function SheetExists(SName As String, _
Optional ByVal Wb As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If Wb Is Nothing Then Set Wb = ThisWorkbook
SheetExists = CBool(Len(Wb.Sheets(SName).Name))
End Function
--
HTH...

Jim Thomlinson


"Jim Jackson" wrote:

I have used a form of the following:

On error goto macrorun
Sheets("Sheetname").Activate

macrorun:
call your macro
--
Best wishes,

Jim


"jkt" wrote:

I need to look for a sheet name within a workbook and run a macro if the
sheet name does not exist. any suggestions?

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
Copying cell info from one sheet to another in the same wkbk shellyjohnson Excel Discussion (Misc queries) 1 June 16th 09 07:09 PM
Large wkbk won't recalc after moving sheet Cody Dawg Excel Discussion (Misc queries) 2 October 17th 06 05:36 PM
How do I replicate an area of a SS onto another sheet in same wkbk Dave Excel Discussion (Misc queries) 2 June 23rd 06 06:55 PM
Move a sheet to last sheet of wkbk AFairRose Excel Programming 1 May 16th 06 02:11 PM
Copy paste WkBk/sheet 1 to multiple wkbks/sheets wrpalmer Excel Programming 1 August 20th 05 03:08 PM


All times are GMT +1. The time now is 12:00 AM.

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"