AppleScripting in Excel X

C

CWMacNut

I have been working on several different AppleScripts for Excel quite
successfully for about a year. So far the only insurmountable hurdle I've had
is in merging cells. In one of my scripts it is essential that I select two
cells and "Merge cells" (Format --> Cells... --> Alignment --> Merge cells).
I have a keyboard command set in my Excel but I cannot get the script to
execute the command. I have searched the web extensively for assistance but
all I have found was a post to this group back in 2002 that asked my question
exactly but never got a satisfactory answer.

Anyone out there? It's driving me nuts here!!

Thanks.
 
P

Paul Berkowitz

I have been working on several different AppleScripts for Excel quite
successfully for about a year. So far the only insurmountable hurdle I've had
is in merging cells. In one of my scripts it is essential that I select two
cells and "Merge cells" (Format --> Cells... --> Alignment --> Merge cells).
I have a keyboard command set in my Excel but I cannot get the script to
execute the command. I have searched the web extensively for assistance but
all I have found was a post to this group back in 2002 that asked my question
exactly but never got a satisfactory answer.

Anyone out there? It's driving me nuts here!!


I have read over and over and over again on the Excel MVP newsgroup, where
all the Excel MVPs (Windows and Mac) hang out (it's private, you cant go
there) that merging cells is BUGGY and should be avoided at all costs. That
means in the UI, by VBA, and by extension AppleScript. So I never do it.
Don't do it. Find another way to do what you want like removing borders
between cells, rather than merging them. I don't want to help you do this
since it's so bad. However I see a 'merge' command in the Table Suite (Excel
2004). You haven't explained what exactly doesn't work with it. You should
not be using AppleScript, ever, to execute keyboard commands. You should be
using it to access the true object model. So first try using the 'merge'
command, and if it doesn't "work", tell us exactly how you tried to use it,
with a simple example, and we'll see what we cam do about it. If you insist
on merging cells...

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
C

CWMacNut

Paul Berkowitz said:
I have read over and over and over again on the Excel MVP newsgroup, where
all the Excel MVPs (Windows and Mac) hang out (it's private, you cant go
there) that merging cells is BUGGY and should be avoided at all costs. That
means in the UI, by VBA, and by extension AppleScript. So I never do it.
Don't do it. Find another way to do what you want like removing borders
between cells, rather than merging them. I don't want to help you do this
since it's so bad. However I see a 'merge' command in the Table Suite (Excel
2004). You haven't explained what exactly doesn't work with it. You should
not be using AppleScript, ever, to execute keyboard commands. You should be
using it to access the true object model. So first try using the 'merge'
command, and if it doesn't "work", tell us exactly how you tried to use it,
with a simple example, and we'll see what we cam do about it. If you insist
on merging cells...

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.

"Buggy" doesn't cover it. It plain ole doesn't work. I'm not trying to
execute a keyboard command because I'm hoping to eventually pass this script
on to other users and calling a keyboard command would be dumb.

I'm using Excel X for Mac and the latest AppleScript.

tell application "Excel ... "
...
select cells A3:A4
merge selection
...
end tell

I've tried all kinds of variations to this (merge cells, merge selected, set
merge of selection to true, etc.). NOTHING works. And when I say it doesn't
work, I mean nothing happens. Zip, zilch, nada, nothing. It completely
ignores the command and keeps going through the script.

I don't WANT to "Find another way to do what you want like removing borders
between cells, rather than merging them." I NEED to merge cells. Period. This
is ridiculous! Just "don't DO it"?!?

Thank you for your input Mr. Berkowitz. Anyone else?

CW
 
J

JE McGimpsey

CWMacNut said:
Thank you for your input Mr. Berkowitz. Anyone else?

It may well be a bug in XLv.X's AppleScript implementation - I did a
quick and dirty attempt and got the same results you did - nothing
happened. AS in v.X always seemed like an afterthought, and a lot of
things didn't get implemented correctly. AS in XL04 is much more robust,
since it hooks into the same object model as VBA, though it's not
perfect.

However, I'd also strongly echo Paul's statement. Merged cells are
nearly always a bad design feature.
 

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