BradleyS
Active Member
- Joined
- Oct 28, 2006
- Messages
- 351
- Office Version
- 2010
- Platform
- Windows
I have this code which works great, in that it tests to see if a specific workbook is open and if not it opens the workbook.
However, I would like to create my own msgbox if the file is not found, but when I add an "else" to the if statement it doesn't find the file!
This is the working code I would like to add a message to:
TargetWb = "My Excel Workbook.xlsx"
For Each Workbook In Workbooks
If Workbook.FullName = TargetWb Then Workbook.Close (False)
Next Workbook
Workbooks.Open(TargetWb).Activate
...the code I have amended below doesn't work, could someone tell me why?
TargetWb = "My Excel Workbook.xlsx"
For Each Workbook In Workbooks
If Workbook.FullName = TargetWb Then
Workbook.Close (False)
else
Msgbox "file not found"
end
Next Workbook
Workbooks.Open(TargetWb).Activate
However, I would like to create my own msgbox if the file is not found, but when I add an "else" to the if statement it doesn't find the file!
This is the working code I would like to add a message to:
TargetWb = "My Excel Workbook.xlsx"
For Each Workbook In Workbooks
If Workbook.FullName = TargetWb Then Workbook.Close (False)
Next Workbook
Workbooks.Open(TargetWb).Activate
...the code I have amended below doesn't work, could someone tell me why?
TargetWb = "My Excel Workbook.xlsx"
For Each Workbook In Workbooks
If Workbook.FullName = TargetWb Then
Workbook.Close (False)
else
Msgbox "file not found"
end
Next Workbook
Workbooks.Open(TargetWb).Activate