Activating workbook from userform

HighAndWilder

Board Regular
Joined
Nov 4, 2006
Messages
80
Hi

I am loading a userform from workbook1 which contains code behind a command button to select another workbook (workbook2)
and load it.

I want the active workbook to be workbook1 but despite activating this workbook the active workbook remains workbook2

If after loading workbook2 I use msgbox to display a name of the workbook, or anything at all in fact, the code to activate workbook1 works.

I have experiencd this before.

I'd like the form to sit on top of the active workbook. Changing the active workbook from the form does not do this.

Any clues anybody?

Thanks
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
4,982
Office Version
365
Platform
Windows
This works for me
- leaving Workbook1 as the active workbook which is visible below the UserForm
Code:
Private Sub CommandButton1_Click()
    Dim wb1 As Workbook: Set wb1 = ThisWorkbook
    Dim wb2 As Workbook: Set wb2 = Workbooks.Open("c:\test\ANYfILE.xlsm")
    wb1.Activate 
End Sub
If above does not help you solve the issue...
Which version of Excel are you using?
What are you doing different?
 
Last edited:

HighAndWilder

Board Regular
Joined
Nov 4, 2006
Messages
80
This works for me
- leaving Workbook1 as the active workbook which is visible below the UserForm
Code:
Private Sub CommandButton1_Click()
    Dim wb1 As Workbook: Set wb1 = ThisWorkbook
    Dim wb2 As Workbook: Set wb2 = Workbooks.Open("c:\test\ANYfILE.xlsm")
    wb1.Activate 
End Sub
If above does not help you solve the issue...
Which version of Excel are you using?
What are you doing different?
Activating a workbook other than the one that the userform is in works fine but I want the userform to still be displayed on top of the active sheet.

It should be so simple as I imagine that it is a common requirement.
 

Forum statistics

Threads
1,086,122
Messages
5,387,973
Members
402,091
Latest member
thomastsiakis

Some videos you may like

This Week's Hot Topics

Top