Weird result


R

Roger B.

I would like to know what is wrong with the following macro.
If Fast05Chts.XLS is closed it works but not if that file is open. Instead I
get a message that the file is open. This is strange when the 'exit sub'
should have prevented this.

Any suggestions would be appreciated.

Roger

Dim File_Name As Variant, book As Object

'Dim book As Variant
File_Name = "Fast05Chts.XLS"
For Each book In Workbooks
If book.Name = File_Name Then
Windows(File_Name).Activate
Exit Sub
End If
Next book

Workbooks.Open Filename:="D:\Fast05\" & File_Name, UpdateLinks:=True
 
Ad

Advertisements

G

Guest

The comparison is case sensitive. Try this code...

Dim File_Name As String
Dim book As Workbook

File_Name = "fast05chts.xls"
For Each book In Workbooks
If LCase(book.Name) = File_Name Then
Windows(File_Name).Activate
Exit Sub
End If
Next book

Workbooks.Open Filename:="D:\Fast05\" & File_Name, UpdateLinks:=True
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top