LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 37
Default How to check to see if a sheet with a particular name exists?

Hi,

VBA newbie here...I have written below code which calls out a sub and func.
Problem is that when the sub procedure is called, which in turn invokes the
function, I am unable to get the correct output. I want to check to see if
the opened file has a worksheet named Impedance and if not, produce a message
saying so...but problem is that I always get "This is not TTM Layer stackup
file" message. What am I doing wrong?

Thanks for help.


Here's the code snippet.

Private Sub cmdbut_Click()

'Make sure that either TTM or DDI is selected
If ttm.Value = False And ddi.Value = False Then
MsgBox "You must select the file type before proceeding", , "File
Not Selected"
Exit Sub
Else
If ttm.Value = True Then
'opening ttm file
ttmfn = Application.GetOpenFilename(FileFilter:="Excel Files
(*.xls), *.xls", _
Title:="Please select a file")
If ttmfn = False Then
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
MsgBox ttmfn, , "File Name"
Application.Visible = False
Workbooks.Open (ttmfn)
End If


Workbooks(1).Activate
'Call DoesSheetExist
'Worksheets("Impedance").Activate

Call WorksheetCheck(ttmfn)

End If
End If

End Sub


'SUB:

Sub WorksheetCheck(ttmfn)
Workbooks(1).Activate
If SheetExists("Impedance") = True Then
MsgBox "Click OK to Continue", vbOKCancel, "Continue"
Else
MsgBox "This is not TTM layerstackup file", , "Wrong File"
End If
End Sub



'FUNCTION:

Function SheetExists(Impedance As String) As Boolean
Dim sheetcount As Integer
Dim t As Integer

SheetExists = False
sheetcount = ActiveWorkbook.Sheets.Count
For t = 1 To sheetcount
If Sheets(t).Name = "Impedance" Then
SheetExists = True
Exit Function
End If
Next t
End Function
 
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
check if sheet exists mohavv Excel Discussion (Misc queries) 1 November 21st 07 01:58 AM
Check if file exists Jon Excel Discussion (Misc queries) 14 October 4th 07 04:57 PM
check if the sheet/tag exists Alex Excel Worksheet Functions 2 March 14th 06 08:58 PM
check if worksheet exists joeeng Excel Worksheet Functions 3 September 7th 05 06:49 PM
Check if a number exists in a range? gkaste Excel Discussion (Misc queries) 2 July 13th 05 08:00 PM


All times are GMT +1. The time now is 01:27 AM.

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

About Us

"It's about Microsoft Excel"