View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Patrick Molloy Patrick Molloy is offline
external usenet poster
 
Posts: 1,049
Default Assistance with macro to determine if a specific worksheet is pres

you can create a simple procedure for this purpose. The code below simply
checks each cell in A. If there's text we assume its a path , concatenate it
to for the full name and use the DIR() function to see if it finds the file.
If it does, then open the file, and check if th esheet is there.

SUB CheckFile()
DIM FN As String
DIM RW as Long
for RW = 2 to 1000
if CELLS(rw,1)<"" then
FN = DIR( cells((RW,1) & "\" & cells(rw,"G") )
if FN <" then
cells(rw,"H") = SheetExists(cells((RW,1) & "\" &
cells(rw,"G"),"Sheet3")
end if
end if
next
END SUB
FUNCTION SheetExists(wbname as string,sheetname as string) as boolean
DIM WB As Workbook
DIM WS As Worksheet
SET WB = Workbooks.Open(wbname)
on error resume next
Set WS = WB.Worksheets(sheetname)
IF Err.Number = 0 then
SheetExists=TRUE
Else
Err.Clear
End If
WB.Close FALSE
END FUNCTION

"Barb Reinhardt" wrote in message
...
I have a list of workbooks and need to determine if a specific worksheet
(say
Sheet3) is present in that workbook. I have the following:

Column A: Y:\BLAH\BLAH\Blah
Column G: filename.xls

The workbook is in the following location
Y:\BLAH\BLAH\Blah\filename.xls

The data starts on row 2 and I can determine the last row of data. I'd
like to have something written to column H if Sheet3 is present in the
workbook.

Thanks in advance,
Barb Reinhardt