Activating workbook from userform

HighAndWilder

Active Member
Joined
Nov 4, 2006
Messages
376
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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:
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,533
Messages
6,114,179
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top