make new named range in Excel

G

gschurr

I am trying to make a new name range in Exce 2004 but it fails.
I have tried many different ways but am getting to the conclusion that
it just may not work. Does anyone have some insight into this? Thanks

Here are a few example of what I've tried:

tell application "Microsoft Excel"
activate
set thisWorkbook to active workbook
set myName to "testing"
set myRange to "=$A1:$A2"
set newItem to make new named item at sheet 1 of thisWorkbook with
properties {name local:myName, value:myRange}
end tell

tell application "Microsoft Excel"
activate
set thisWorkbook to active workbook
set myName to "testing" as Unicode text
set myRange to "=$A1:$A2" as Unicode text
set newItem to make new named item at thisWorkbook with properties
{name local:myName, value:myRange}
end tell

tell application "Microsoft Excel"
activate
set thisWorkbook to active workbook
set newItem to make new named item at thisWorkbook
end tell
 
J

JE McGimpsey

This works for me:

tell application "Microsoft Excel"
set name of range "A1:A2" of active sheet of active workbook to
"testing"
end tell
 
G

gschurr

Yes, me too. What I can't get to work is to make a new named item as
you can see from my Applescript snippets. Did you try that?
 
J

JE McGimpsey

Yes, me too. What I can't get to work is to make a new named item as
you can see from my Applescript snippets. Did you try that?

No. Since you wrote "I am trying to make a new name range in Exce 2004",
that's what I did.

However, you can see that naming a range makes it a named item of the
workbook...

tell application "Microsoft Excel"
set name of range "A1:A2" of active sheet of active workbook
to "testing"
set a to named item "testing" of active workbook
set b to value of a
end tell

which returns "=Sheet1!$A$1:$A$2" in b
 
G

gschurr

Oh I see - you are not explicitly creating the item with the make
command, but getting it by naming a range directly. I'll try this.
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top