View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Gert-Jan Gert-Jan is offline
external usenet poster
 
Posts: 49
Default Check if file exists / open it

For some extra functions I created a second workbook (wb2.xls). In Sheet1!A1
(wb1.xls) is the filename (created with a formula). This works fine:

Sub Test1()
Workbooks.Open Filename:= _
Range("Sheet1!A1").Value
End Sub

But this doesn't work:

Sub Test2()
Option Explicit
Dim mywkbk As Workbook
Dim myfile As String
myfile = Range("sheet1!A1").Value
If Dir(myfile) = "" Then
MsgBox "that doesn't exist!"
Exit Sub
Else
Set mywkbk = Workbooks.Open(myfile)
End If
End Sub

Can someone help??