Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Further to my last thread - Check for worksheet in a closed file

Hi all,
I got the function below from Bob Phillips yesterday and would like to
know if it is possible for it to give me the name of the sheet that it
finds ?

Any help would be much appreciated...

Function IfSheetExists(FileName As String, sh As String) As Boolean
Dim oConn As Object



'FileName = "\\nv09002\tpdrive\Projects\General\50_Comparisons \KTL's\" &
myKTLih & ".xls"
'sh = Worksheets("TOOL TRACKING")

Set oConn = CreateObject("ADODB.Connection")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & FileName & ";" & _
"Extended Properties=Excel 8.0;"

On Error Resume Next
oConn.Execute "SELECT 1 FROM [" & sh & "$] WHERE 0=1"
IfSheetExists = (Err.Number = 0)

oConn.Close
Set oConn = Nothing

End Function


Best regards,

Les Stout

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Further to my last thread - Check for worksheet in a closed file

On Dec 4, 2:50 pm, Les Stout wrote:
Hi all,
I got the function below from Bob Phillips yesterday and would like to
know if it is possible for it to give me the name of the sheet that it
finds ?

Any help would be much appreciated...

Function IfSheetExists(FileName As String, sh As String) As Boolean
Dim oConn As Object

'FileName = "\\nv09002\tpdrive\Projects\General\50_Comparisons \KTL's\" &
myKTLih & ".xls"
'sh = Worksheets("TOOL TRACKING")

Set oConn = CreateObject("ADODB.Connection")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & FileName & ";" & _
"Extended Properties=Excel 8.0;"

On Error Resume Next
oConn.Execute "SELECT 1 FROM [" & sh & "$] WHERE 0=1"
IfSheetExists = (Err.Number = 0)

oConn.Close
Set oConn = Nothing

End Function

Best regards,

Les Stout

*** Sent via Developersdexhttp://www.developersdex.com***


Hi
The input sh to the function is the name of the sheet, or have I
missed something? Why would you need the function to return it if you
already know it??
Maybe if you are inside a loop???

For each Sh in Activeworkbook.worksheets
If IsSheetExists(FileName, Sh.Name) then
FoundSheetName = Sh.Name
End If
Next Sh

regards
Paul
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Further to my last thread - Check for worksheet in a closed file

Hi Paul, no the (sh) is the sheet that i am looking for. It is possible
to create a "KTL" with different sheet names, which has different data
on it. So just want to advise the user that the file is there but
incorrect as the sheet has a different name.

Best regards,

Les Stout

*** Sent via Developersdex http://www.developersdex.com ***
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
Check for worksheet in closed workbook Les Excel Programming 4 December 3rd 07 04:45 PM
distributed vba project - multiple thread / concurrent file access [email protected] Excel Programming 4 June 15th 07 05:15 AM
CAN I IMPORT DATA FROM A CLOSED FILE TO A NEW WORKSHEET Paul Excel Discussion (Misc queries) 1 January 11th 07 02:30 PM
How can I check the file size of each worksheet in an Excel Doc Chris1707 Excel Discussion (Misc queries) 2 January 3rd 07 06:31 PM
Check to see if Excel has closed Robert A. Boudra Excel Programming 7 November 18th 04 01:00 AM


All times are GMT +1. The time now is 05:19 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"