Need to switch focus back to workbook from VBA form

I have an Excel userform with a Part Number textbox that users enter data to, (a SQL db search uses this data to return a query) .
The form works just fine when users do not switch from the workbook that contains the form (MORF.xls) to another workbook.
Problem happens when they open the form, then switch to another workbook (to copy/paste their Part Number), then paste the data to the form. The Activeworkbook is no longer MORF.xls, thus all my workbook references (eg; Set SelectedSites_AllChk = Range("E7")) refer to the other workbook which is active.

What I need is a method to publicly declare the name of the MORF.XLS workbook, and make this available to the code in the userform.

Note that I have a Sub in a Module (Sub ShowForm()) which shows the form, then a button on the form which runs the SQL query.
I believe I need to be able to assign the workbook name in the ShowForm Sub, then pass this to a workbook variable in the userform.
Thanks a lot,
Fergal
fjkilkenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

then use

Set SelectedSites_AllChk = ThisWorkbook.ActiveSheet.Range("E7")

'ThisWorkbook' refers to the Wb where the macro is running

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fjkilkenAuthor Commented:
Wow! that was fast....
Such a simple but 100% effective fix - thanks a lot Rgonzo1971!!!
0
fjkilkenAuthor Commented:
perfect - thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.