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
AMixMasterTraining DeveloperAsked:
Who is Participating?
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,

If the Workbook is already open

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

Regards
0
Roy CoxGroup Finance ManagerCommented:
Clarify what you mean by remote. Is it on a network and will it be open?
0
AMixMasterTraining 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
0
Rgonzo1971Commented:
then try

Set wb = Workbooks("myWorkbook.xlsm")
 Intersect(wb.ActiveSheet.UsedRange, wb.ActiveSheet.Range("A:G")).SpecialCells(xlCellTypeVisible).Name = "TheName"
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
AMixMasterTraining DeveloperAuthor Commented:
Works like a charm :)
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.