tljenkin
Board Regular
- Joined
- Jun 14, 2007
- Messages
- 147
Hi All
I have the code below but instead of defining the full name of the workbook which will change as different versions are created, can I get VBA to switch to that workbook using the partial name "Actuals Repository" and a wildcard? OR if possible for excel to just attempt to open the file, realise it is open, dont open another copy and skip the notification that usually pops up asking if you would like to open the file again.Thanks
Sub IsItOpen()
Dim Response As Integer
Response = MsgBox(prompt:="Is the Actuals repository already open?", Buttons:=vbYesNo)
If Response = vbYes Then
Windows("Actuals Repository*.xls").Activate
End If
If Response = vbNo Then
Dim FileToOpen As Variant, File As Variant, MasterWb As Workbook, Wb As Workbook
On Error GoTo 0
Set MasterWb = ThisWorkbook ' or BPM Model latest version presently open
FileToOpen = Application.GetOpenFilename(FileFilter:="All Excel Files (*.xlsm), actuals*.xlsm", Title:="Where is the Actuals Repository?", MultiSelect:=False)
Application.ScreenUpdating = False
' Exit if user exits dialog
If FileToOpen = False Then Exit Sub
' Open file (Wb), copy weekly analysis from Repository (several sheets) to BPM
Set Wb = Workbooks.Open(FileToOpen)
Wb.Activate
End If
End Sub
I have the code below but instead of defining the full name of the workbook which will change as different versions are created, can I get VBA to switch to that workbook using the partial name "Actuals Repository" and a wildcard? OR if possible for excel to just attempt to open the file, realise it is open, dont open another copy and skip the notification that usually pops up asking if you would like to open the file again.Thanks
Sub IsItOpen()
Dim Response As Integer
Response = MsgBox(prompt:="Is the Actuals repository already open?", Buttons:=vbYesNo)
If Response = vbYes Then
Windows("Actuals Repository*.xls").Activate
End If
If Response = vbNo Then
Dim FileToOpen As Variant, File As Variant, MasterWb As Workbook, Wb As Workbook
On Error GoTo 0
Set MasterWb = ThisWorkbook ' or BPM Model latest version presently open
FileToOpen = Application.GetOpenFilename(FileFilter:="All Excel Files (*.xlsm), actuals*.xlsm", Title:="Where is the Actuals Repository?", MultiSelect:=False)
Application.ScreenUpdating = False
' Exit if user exits dialog
If FileToOpen = False Then Exit Sub
' Open file (Wb), copy weekly analysis from Repository (several sheets) to BPM
Set Wb = Workbooks.Open(FileToOpen)
Wb.Activate
End If
End Sub