pcc
Well-known Member
- Joined
- Jan 21, 2003
- Messages
- 1,382
- Office Version
- 2021
- Platform
- Windows
I have hundreds of Excel files, but there are a handful that I use frequently. To this end, I have (In my personal.xls file) a userform, which, when loaded, displays those files as optionbutton captions (see image). I select the file required by clicking the optionbutton, then clicking the command button that says "Go". The code attached to this button is as follows:
The selected file opens up OK, but then Excel reverts back to showing the personal.xls window, not the window for the file that has just been opened. I don't understand why this happens. I recently ugraded
from Excel 2002 to Excel 2021, and in Excel 2002 it opened the file and stayed displaying that window.
Any suggestions as to why this might be happening, and, more importantly, how to overcome this, so that the file that has just been opened becomes the active window?
VBA Code:
Private Sub CommandButton2_Click()
For Each but In Me.Controls
If but.name Like "Option*" Then
If but.Value = True Then
Workbooks.Open "C:\users\peter\data\xl\" & but.Caption & ".xlsm"
End
End If
End If
Next but
End Sub
The selected file opens up OK, but then Excel reverts back to showing the personal.xls window, not the window for the file that has just been opened. I don't understand why this happens. I recently ugraded
from Excel 2002 to Excel 2021, and in Excel 2002 it opened the file and stayed displaying that window.
Any suggestions as to why this might be happening, and, more importantly, how to overcome this, so that the file that has just been opened becomes the active window?