Peter Davison
Active Member
- Joined
- Jun 4, 2020
- Messages
- 435
- Office Version
- 365
- Platform
- Windows
I have this code (as part of a larger code) for checking if a specific file is open.
The only problem I have is that even though the file is open it tries to open it again and then crashes.
Any thoughts why it tries to open the file again?
Appreciate any help on this one.
'declare variables
Dim wb As Workbook
Dim FilePath As String
FilePath = "C:\cluster insight macro\Breakfast Foods Combined Raw Data.xlsm"
For Each wb In Workbooks
If wb.Name = "Breakfast Foods Combined Raw Data.xlsm" Then
'this message will appear if the open workbooks is Breakfast Foods Combined Raw Data.xlsm
MsgBox "Main Data File is Open"
returnval = "fileOpen"
End If
Next
If returnval <> "fopen" Then
Workbooks.Open FilePath, UpdateLinks:=0
End If
The only problem I have is that even though the file is open it tries to open it again and then crashes.
Any thoughts why it tries to open the file again?
Appreciate any help on this one.
'declare variables
Dim wb As Workbook
Dim FilePath As String
FilePath = "C:\cluster insight macro\Breakfast Foods Combined Raw Data.xlsm"
For Each wb In Workbooks
If wb.Name = "Breakfast Foods Combined Raw Data.xlsm" Then
'this message will appear if the open workbooks is Breakfast Foods Combined Raw Data.xlsm
MsgBox "Main Data File is Open"
returnval = "fileOpen"
End If
Next
If returnval <> "fopen" Then
Workbooks.Open FilePath, UpdateLinks:=0
End If