How to create a named range in a remote workbook/worksheet

To create a named range within the active workbook/sheet I use:

intersect(activesheet.usedrange,Range("A:G")).SpecialCells(xlCellTypeVisible).Name = "TheName"

How could I modify this to create a named range for the used cells in a worksheet within a remote workbook
Allen PrinceTraining DeveloperAsked:
Who is Participating?

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

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.


If the Workbook is already open

set wb = Workbooks("myWorkbook.xlsm")
intersect(wb.activesheet.usedrange,Range("A:G")).SpecialCells(xlCellTypeVisible).Name = "TheName"

Roy CoxGroup Finance ManagerCommented:
Clarify what you mean by remote. Is it on a network and will it be open?
Allen PrinceTraining DeveloperAuthor Commented:
the sheet is open on the local computer
it works if I place the code in the same workbook

if tied to a sheet in another workbook
I receive the error:

Run-time error 1004
Application-defined or Object-defined error

or in a module within a separate workbook:
Run-time error 1004
Method 'Intersect' of object '_Global failed
then try

Set wb = Workbooks("myWorkbook.xlsm")
 Intersect(wb.ActiveSheet.UsedRange, wb.ActiveSheet.Range("A:G")).SpecialCells(xlCellTypeVisible).Name = "TheName"

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
Allen PrinceTraining DeveloperAuthor Commented:
Works like a charm :)
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.