Test for worksheet in a closed workbook.
Posted on 2007-10-09
I need to test to see if a worksheet exists in a closed workbook. I am currently using the code I found posted on this site that allows you to access data from a closed workbook;
Private Function GetValue(path, file, sheet, ref)
' Retrieves a value from a closed workbook
Dim arg As String
' Make sure the file exists
If Right(path, 1) <> "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
' Create the argument
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(ref).Range("A1").Address(, , xlR1C1)
' Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)
however, I have not been able to modify it to only test for the existance of a specified worksheet in the closed workbook. Any help would be greatly appreciated?