flea333
06-25-2010, 01:01 PM
I'm not sure why this code isn't working. wBook never seems to be set to anything regardless if the file is open or not, it will open the file. Then in the future when I use wBook.Close, it won't work because wBook is Empty.
Dim Fname As Variant
Fname = Application.GetOpenFilename("Excel Files (*.xls; *xlsx), *.xls; *.xlsx")
Filename = CStr(Fname)
If Fname <> False Then
On Error Resume Next
Set wBook = Workbooks(Filename)
If wBook Is Nothing Then
Workbooks.Open Filename:=Fname, ReadOnly:=True
'Instead of opening just grab data out of file
Else
MsgBox ("This file is already open. Verify the data is not modified, close and rerun macro")
End If
Dim Fname As Variant
Fname = Application.GetOpenFilename("Excel Files (*.xls; *xlsx), *.xls; *.xlsx")
Filename = CStr(Fname)
If Fname <> False Then
On Error Resume Next
Set wBook = Workbooks(Filename)
If wBook Is Nothing Then
Workbooks.Open Filename:=Fname, ReadOnly:=True
'Instead of opening just grab data out of file
Else
MsgBox ("This file is already open. Verify the data is not modified, close and rerun macro")
End If