Finding Active Workbook and Worksheet

tlawson1

Board Regular
Joined
Jun 15, 2003
Messages
69
Hi All

I have a UserForm with its properties Show Modal set to False so the user can use another workbook while my UserForm is active.

For example they may have Book2 open and be on Sheet1

Once my code has run I wish to return to their active workbook and worksheet but I am unsure how to Dimension this

Dim myCheck as ????
myCheck =Application.ActiveWorkbook.ActiveSheet.Name

????? Any help please
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Something like this....

Code:
Dim myBook As String
Dim mySheet As String

myBook = ActiveWorkbook.Name
mySheet = ActiveSheet.Name

Worksheets(myBook).Activate
Sheets(mySheet).Select
 
Upvote 0
You can return to the Workbook your Code is running in by referencing "ThisWorkbook".

Thisworkbook.Worksheets("Sheet1").select
 
Upvote 0
This is what I have been doing....

Application.ThisWorkbook....To use my code but didn't know how to return to the workbook the user was currently on.

Will be writing all this down for future use though

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,896
Members
452,948
Latest member
Dupuhini

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