Activating workbook from userform

HighAndWilder

Board Regular
Joined
Nov 4, 2006
Messages
173
Office Version
365
Platform
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
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,385
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
173
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?
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,867
Messages
5,489,365
Members
407,686
Latest member
Chuck1960

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top