Ensure workbook is always the active workbook

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,064
Office Version
  1. 2016
Platform
  1. Windows
On my useform I have several objects like listbox, multipages and buttons, is it possible to ensure that if ANY object is clicked on a userform or the userform itself is clicked then the correct WORKBOOK that contains the useform will become the ACTIVE workbook.

Users are getting error messages, mainly due to the correct workbook not being the active workbook. This happens when the user has several workbooks open and the correct workbook with the userform IS NOT the active workbook the code crashes as script out of range.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
77,703
Office Version
  1. 365
Platform
  1. Windows
Safest option is to preface all sheets and ranges with the workbook name & sheet name. That way you are guaranteed to be looking at the correct sheet.
 

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,064
Office Version
  1. 2016
Platform
  1. Windows
Thanks, Fluff. I did think of that but its a big job I was hoping for a quick fix. one click to do it all
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
77,703
Office Version
  1. 365
Platform
  1. Windows
I was hoping for a quick fix. one click to do it all
Very much doubt that's possible. Even if it is, one of the users will find a way to break it.
 

ebea

Active Member
Joined
Jul 12, 2008
Messages
283
Office Version
  1. 2021
Platform
  1. Windows
On my useform I have several objects like listbox, multipages and buttons, is it possible to ensure that if ANY object is clicked on a userform or the userform itself is clicked then the correct WORKBOOK that contains the useform will become the ACTIVE workbook.

Users are getting error messages, mainly due to the correct workbook not being the active workbook. This happens when the user has several workbooks open and the correct workbook with the userform IS NOT the active workbook the code crashes as script out of range.
I had a similar problem, and found out, that it was related to the Multipage selections, itself. If a selected Multipage was selected, and the Sheet belonging to that, was NOT the active, I got an error (as you). So my solution was, that for each Multipage, I did Set the Sheet for that actual Page, on the Form. That solwed the problem for me.
 

Forum statistics

Threads
1,176,086
Messages
5,901,305
Members
434,886
Latest member
qazibelal

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
Top