LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Check a workbook exists before opening

Hi all,

I have a workbook that opens another workbook that can be stored in any
location (however the filename will always be the same). I have managed to
write the code to allow the user to select the location of the second
workbook. However, in the interests of completeness I have attempted to
write a function to check the second workbook exists in the selected folder
(this was based on a function that checks a worksheet exists)

Function wbExists(ByRef wbname As String) As Boolean
Dim wb As Workbook
wbExists = False
For Each wb In sfoldername
If wb.Name = wbname Then wbExists = True
Next
End Function


and within my code for workbook 1

If wbExists(sfoldername & "\test2.xls") = True Then
Workbooks.Open sfoldername & "\test2.xls"
Else
MsgBox "Test2 data sheet not found in selected folder"
Exit Sub
End If

the variable sfoldername is a general declaration and contains the file path
eg. C:\folder1

When I run the code I get a compile error which states For Each may only
iterate over a collection object or an array.

Can anyone help me out of this little hole please.

Regards and Thanks

Mick


 
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
How to check to see if a sheet with a particular name exists? Varun Excel Worksheet Functions 3 January 25th 09 01:41 PM
Help - How to check if value exists in closed workbook? c mateland Excel Programming 3 April 16th 07 03:05 AM
Check if a sheet exists in a file, without opening that file Bogdan Excel Programming 5 March 9th 07 01:46 PM
Check if sheet exists in a closed workbook FrigidDigit[_2_] Excel Programming 2 October 25th 05 06:44 AM
check if worksheet exists joeeng Excel Worksheet Functions 3 September 7th 05 06:49 PM


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