Link to home
Start Free TrialLog in
Avatar of Allen Prince
Allen PrinceFlag for United States of America

asked on

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
Avatar of Rgonzo1971
Rgonzo1971

Hi,

If the Workbook is already open

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

Regards
Clarify what you mean by remote. Is it on a network and will it be open?
Avatar of Allen Prince

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Works like a charm :)