Bug with cell merging in tables using Applescript

Version: 2008
Operating System: Mac OS X 10.6 (Snow Leopard)
Processor: Intel

Once you have merged cells in a table in Word 2008 using Applescript, any further reference to the table's cells in the script produce an error. <br><br>As an example, open Word 2008 and run this script: <br>
tell application &quot;Microsoft Word&quot; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;make new table at active document with properties {number of rows:4, number of columns:4} <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set mytable to table 1 of active document <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;merge cell (cell 1 of row 1 of mytable) with (cell 1 of row 2 of mytable) <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;merge cell (cell 1 of row 3 of mytable) with (cell 1 of row 4 of mytable)&#09; <br>
end tell <br><br>The script inserts a 4x4 table, merges the left hand cells of rows 1 and 2 as it should, then fails with error &quot;Microsoft Word got an error: The object you are trying to access does not exist&quot; number -1728 from cell 1 of row 3 of table 1 of active document. <br><br>Any reference to a cell made in an Applescript after merging cells will produce the error. For example substituting "select (cell 3 of row 3 of mytable)" for the last line of the script produces the same error on running the script. <br><br>Is this a bug or am I missing something?
0
backroomboys
3/24/2010 3:29:12 PM
mac.office.word 1676 articles. 1 followers. Follow

3 Replies
2306 Views

Similar Articles

[PageSpeed] 39

AFAICS you cannot reference row objects within a table once you have 
merged cells in a column and you cannot reference column objects once 
you have merge two cells in a row.

You can however do this:

tell application "Microsoft Word"
	make new table at active document with properties {number of rows:4, 
number of columns:4}
	set mytextobj to text object of table 1 of active document
	merge cell (cell 1 of mytextobj) with (cell 5 of mytextobj)
	merge cell (cell 9 of mytextobj) with (cell 13 of mytextobj)
end tell

but you will obviously need to keep track of how the cell numbers change 
as you go along!

(FWIW I do not know whether you would get this problem with rows etc. in 
Word 2004 + VBA or the Windows version of Word)

Peter Jamieson

http://tips.pjmsn.me.uk

On 24/03/2010 15:29, backroomboys@officeformac.com wrote:
> tell application "Microsoft Word"
>          make new table at active document with properties {number of
> rows:4, number of columns:4}
>          set mytable to table 1 of active document
>          merge cell (cell 1 of row 1 of mytable) with (cell 1 of row 2
> of mytable)
>          merge cell (cell 1 of row 3 of mytable) with (cell 1 of row 4
> of mytable)
> end tell
0
Peter
3/24/2010 7:36:12 PM
I'm going to stick my neck way out on the chopping block here and suggest
that you are destroying the object you are trying to reference.

When you "set mytable to table 1..." you have set a reference to an area in
memory.

Then when you do the merge, the shape of the table changes in memory and the
object is destroyed.

I am guessing (guessing!!) that if you re-write the code without the
"set..." statement, it will work (very slowly!) because then you will have
to resolve cell 1 of row 1 of mytable table 1 of active document on each
iteration.

I seem to remember that Word has an issue with cells in rows in a table.
You may be better to address the cell directly (cell 11 of table 1).

Hope this helps

On 25/03/10 2:29 AM, in article 59bb5d7d.-1@webcrossing.JaKIaxP2ac0,
"backroomboys@officeformac.com" <backroomboys@officeformac.com> wrote:

> Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel
> Once you have merged cells in a table in Word 2008 using Applescript, any
> further reference to the table's cells in the script produce an error.
> 
> As an example, open Word 2008 and run this script:
> tell application "Microsoft Word"
>         make new table at active document with properties {number of rows:4,
> number of columns:4}
>         set mytable to table 1 of active document
>         merge cell (cell 1 of row 1 of mytable) with (cell 1 of row 2 of
> mytable) 
>         merge cell (cell 1 of row 3 of mytable) with (cell 1 of row 4 of
> mytable)  
> end tell 
> 
> The script inserts a 4x4 table, merges the left hand cells of rows 1 and 2 as
> it should, then fails with error "Microsoft Word got an error: The object you
> are trying to access does not exist" number -1728 from cell 1 of row 3 of
> table 1 of active document.
> 
> Any reference to a cell made in an Applescript after merging cells will
> produce the error. For example substituting "select (cell 3 of row 3 of
> mytable)" for the last line of the script produces the same error on running
> the script. 
> 
> Is this a bug or am I missing something?

 --

The email below is my business email -- Please do not email me about forum
matters unless I ask you to; or unless you intend to pay!

John McGhie, Microsoft MVP (Word, Mac Word), Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. | Ph: +61 (0)4 1209 1410 | mailto:john@mcghie.name


0
John
3/24/2010 11:32:53 PM
I tried Peter's script and the second merge was't quite right - it merged cells in rows 3 and 4 of column 2, rather than column 1. From what you both say, it looked like the first merge altered the numbering of cells below the merge, thereby causing the second merge to go wrong. <br><br>I reversed the order of the merges in the script, so that the first merge was at the bottom of the table and the second was at the top and achieved merging of the cells in the left-hand column as I wanted. <br><br>Thanks for solving this one so quickly! I'll use cell numbering and the bottom to top order of merging in future.
0
backroomboys
3/25/2010 10:01:51 AM
Reply:

Similar Artilces:

How to automatically add a worksheet using macro?
Can I add adding a worksheet in a macro? How do I do that? Ex. I create a new macro. One of the steps in my macro is to insert a new worksheet. Dim NewWks as worksheet set NewWks = worksheets.add with newwks .name = "Your New Name Here" .range("A1").value = "Hi there" End with eva wrote: > > Can I add adding a worksheet in a macro? How do I do that? > Ex. I create a new macro. One of the steps in my macro is to insert a new > worksheet. -- Dave Peterson Thank you "Dave Peterson" wrote: > Dim NewWks as worksheet > set Ne...

Strange bug
Hi, I have a strange bug, in a class I wrote for printing... There's a place where the class is calling a function to do the printing on a CDC, and right after that it calls CDC::EndPage. The very strange thing happens: The function who draw, can do anything, except LineTo or MoveTo, because if I do even a single MoveTo, the execution fails on CDC::EndPage (Unhandled exception at 0x00000000... Access violation...) I tried to replace the printing function with a compact function who only does a MoveTo(1,1), and it is the same result. But if I do the drawing without a sub-function, ...

Need pivot table data to return the value rather than sum, count,
Is there any way to return the data itself into the pivot table data? I used to be able to return the value, not the sum, count or calculation. Now there is not a selection for it in the drop-down box. ...

Parent of item in Pivot table
Hello NG, i got an Excel 07 pivot table with the dimensions Region, Country, City I now want to get the "parents" of a double-clicked item. Example Europe UK London If a users double-klicks on "London" i need to somehow get the "UK" and "Europe" value via VBA. I catched the OnDoubleClick event of the worksheet and set cancel=true to avoid drilling down that normally would occur when double-clicking an item in a pivot, which works fine. I tried to adress the "parents" via ParentItem, but id did not succeed. Can ...

Using SQL Server Reporting Services for Form-Type Reports
I'm wondering if I'm missing something with SSRS. Creating a report to print a single invoice or work order or purchase order is easy. However, creating a report to print a range of items, like invoices, seems to require an inordinate amount of work. From what I see, you have to do everything inside a table in the body of the report. Is this right? -- Charles Allen, MVP I think you could use a sub-report to that. -- Tim Foster "Charles Allen" wrote: > I'm wondering if I'm missing something with SSRS. Creating a report to print > a single invoice o...

Any way to know if a site uses all precompiled DLLs?
The abridged reason for wondering what I'm wondering is that there is a person who wants to outsource some work to someone else who wants to outsource it to me, leaving me about three levels removed from the client in question. And by the time I explained the reasons I need to know and it goes back through the chain, I fear a bit of whisper-down-the-lane would distort what I'm asking. So, is there any info that one can collect from a web server about a web application that would tell me if the aspx files use run-time aspx.cs/vs files, source code in the app_code folde...

How Can I make a cell flash in Excel
I am looking to highlight certain cells in a column of data and would be helpful to make them flash, as oposed to just standard formatting Hi flashing would require VBA (using for example the OnTime method). But I strongky recommend against it: - slows down Excel - has IMHO nothing to do with serious spreadsheets - requires VBA and won't work if macros are disabled If you still want to go on with this search the Google archives for 'blinking cell' "Cumbo" wrote: > I am looking to highlight certain cells in a column of data and would be > helpful to make them ...

Sync to cell phone
Sync to cell phone using wmp 11 use to work. Now problem when sync to cell phone 50 music from library and 1st song 100% complete then it would error out and the rest also. The phone would restart it after the error and back to sync again. I try to reapply wmp11 see if it miss apps/patch didnot work. ...

Merged Outlook CRM Contacts
I have been working with my users eliminating duplicated contact entries in Outlook/CRM. I have been advising the users to Merge the Contact record, because our sales people don't have the "delete" function available to them. From CRM this is working wonderful, but once the record has been merged the Outlook record is no longer tracked in CRM. Any suggestion or thoughts would be greatly appreciated. r/ Anthony ...

Getting the cell reference
How can I automatically/ continously get the cell reference to the last cell in a particular column, that contains text? Any help would be appreciated! *Thanks. :) * -- DuncanG ------------------------------------------------------------------------ DuncanG's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=16398 View this thread: http://www.excelforum.com/showthread.php?threadid=277691 Hi see for various methods depending on your data structure and performance requirements: http://www.xldynamic.com/source/xld.LastValue.html "DuncanG" wrote: >...

Using textbox using a variable
Hi Guys, I need to know, if I have a variable call (txtField) cointaining the name of a field of my form ex. txtField="Day1Week2", I want to move 3 to Day1Week2 textbox on my form using txtField. Thanks Maracay wrote: >I need to know, if I have a variable call (txtField) cointaining the name >of a field of my form ex. txtField="Day1Week2", I want to move 3 to Day1Week2 >textbox on my form using txtField. Since variables are strictly a VBA item, they can only be used in a VBA procedure. Use this kind of syntax: Me(txtfield) = 3 -- Mars...

Mail Merge #7
Does anyone know how to do a sophisticated Mail Merge from Outlook? Are there fields for personalized salutations? And if the name should be addressed Mrs. or Ms. or if two people are married but have different last names is there a way to enter that into the contact info? Does anyone know? please help. Outlook+Word can merge whatever data you put into an Outlook item, including custom fields. You can set up additional fields on the All Fields tab. For best results, start the merge from your Contacts folder with the Tools | Mail Merge command. -- Sue Mosher, Outlook MVP Author of ...

bug in XmlSerializer.FromTypes()?
It seems that XmlSerializer.FromTypes() method cannot handle inner class properly .. or is there anything I did wrong? The following code will throw a reflection exception at FromTypes() method. Is there a work-around? using System; using System.Xml; using System.Xml.Serialization; namespace My { /// <summary> /// Summary description for Class1. /// </summary> class Class1 { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { ...

Can you have cells "trade places"?
I dont know if this is possible, but I want to be able to move a cell on top of another cell and have them trade places instead of just delete the existing cell. Is this possible? You could record a Macro to move/copy A1 to C1 and then move/copy B1 to A1, and then move/copy C1 to B1.......... Vaya con Dios, Chuck, CABGx3 "Jimmy" <anonymous@discussions.microsoft.com> wrote in message news:096E45D4-AEC4-4A25-997D-E49102F28A08@microsoft.com... > I dont know if this is possible, but I want to be able to move a cell on top of another cell and have them trade places instead o...

How can I restrict cell data display to column width?
I would like to print my spreadsheet and restrict the data display to the column width so that no column's empty cells are not covered with wide data in adjacent column cells. Is there a way to do this? (Text control "wrap text" and "shrink to fit" don't work for me.) ...

BUG: Outlook treats new message window as a dialog box
Applies to: Outlook 2000/2002/2003 (possibly also earlier versions, but not tested) Tested with: OL 2000 on Windows 98 SE OL 2003 on Windows XP Pro SP2 SYMPTOMS When Outlook is called externally to create a new message, it will treat the new message window as a dialog box. This has the consequence that the whole application is locked until one disposes of the "dialog box" either by sending the message or closing it. An alternative scenario is such that Outlook is not running, and the call is made to create a new message. In such case, if one attempts to start Outlook, one gets the...

bold text of referenced cell show in formula cell
I have a VLookup formula to another worksheet, but I need the bold text of the referenced cells to show up as bold in the formula cell. I understand you can do that with Conditional formating if the data is in the same worksheet, but my data is in a different worksheet and it gives me an error. You can refer to another sheet for CF if you define a name for a cell on other the sheet. i.e. defined name "apple" refers to Sheet2A1 On Sheet1 in B2 CF>Formula is: =B2=apple BUT..........you cannot CF the results of a formula based upon just whether or not th...

Publisher 07 Mail Merge
Master Document has 3 duplicate documents similar to a postcard. I am attempting to mail merge into the master doc. I am using simple fields such as name address etc. How can I creat a mail merge of multiple recipients(3) on one document ie. Name1, Name2 Name 3 - address1, address2.. you get the picture. When you mail merge you can only have one card on the screen. What size are the cards? When you are ready to print, select multiple pages per sheet. There is a print preview on the print screen. Help here http://office.microsoft.com/en-us/publisher/CH100502901033.aspx -- Mary Sa...

Forwarding messages using Folder Assistant
Hi, We upgraded a few months ago from Exchange 5.5 to Exchange 2000. We had setup the folder assistant on a public IT project calendar to forward ALL messages (new entries in the calendar) to our IT team. This worked fine on 5.5 but when we upgraded to EX2000, it stopped working. Does anyone know what the issue could be? Does EX2000 "all messages" differ from 5.5's? Could it be some kind of permission issue? I did get forwarding to work by entering all of our IT teams names in the "From" field. So when someone from IT enters a calendar event, the whole IT team ge...

Miscellaneous words appear in Excel 2002 cells
I am working on an Excell 2002 workbook and when I put my cursor in a cell , spurious words get entered into the cell e.g. "and thee the and ...." is one example. I have cable modem and it feels like "someone" has taken control of my PC - by the way I have also noticed this hapening in MS Word but is not as bad as Excel - can some one help. thanks KK Have you enabled speech tools? Click Tools / Speech and examine your options. /i. "KK" <anonymous@discussions.microsoft.com> wrote in message news:061d01c39d1c$36fc85f0$a601280a@phx.gbl... > I am w...

how to copy cell with remark
Hi All How to copy cell with remark ? Excel : 2003 moonhkt On 1=E6=9C=8813=E6=97=A5, =E4=B8=8A=E5=8D=8810=E6=99=8226=E5=88=86, moonhkt= <moon...@gmail.com> wrote: > Hi All > > How to copy cell with remark ? > > Excel : 2003 > > moonhkt More Infrormation. I open two instance of Excel.exe. For compare excel side by side verify and copy. The remark or comment can not copy between 2 excel instance. When open 2 file in one Excel.exe, the comment can able to copy. After serious thinking leung eric wrote : > On 1月13日, 上�͈10時26�Ȇ, moonhkt <moon...@gmail.com>...

problem using tab
When I hit the tab button the selection jumps several columns over instead of going to the next column. What's strange is that this seems to happen only on one computer in the network and not on the others. The document is shared so I think it is maybe the formatting for that computer's excel. Does anyone know what is going on? Hi Tools > Options > Transition, uncheck "transision navigation keys". HTH. Best wishes Harald (Not knowing what's going on, just how to get rid of it :-) "officebug" <officebug@discussions.microsoft.com> skrev i me...

To display number in text format in cells
I have a sequence of digits like 5026555306553 I entered in a cell and when the cursor left the cell it displays as 5.02656E+12 How do I set the cell or the whole spreadsheet to display as text rather than this format? Change the cell format to either: Number Accounting or Currency. -- HTH, RD --------------------------------------------------------------------------- Please keep all correspondence within the NewsGroup, so all may benefit ! --------------------------------------------------------------------------- "Man T" <alanpltse_NOSPAM@yahoo.com.au> wrote in messag...

Change data from one cell to another cell
How can I automatically change data entered in cell A1 (32454521) into a dollar amount in cell A2 ($16.25)? Thanks for your guidance! Since you don't give much detail, my GUESS is that this is some part number and you want to lookup the price. If so, look in the help index for VLOOKUP -- Don Guillett SalesAid Software dguillett1@austin.rr.com "tmitchell" <tmitchell@discussions.microsoft.com> wrote in message news:4F90AD88-3124-412F-89C9-B593198E80C3@microsoft.com... > How can I automatically change data entered in cell A1 (32454521) into a > dollar amount in ce...

Mail Merge Publisher 20002 with Outlook 2000 Fails
I have Publisher 2002 and can not get Publisher to recognize Outlook 2000 files.I am getting the error message of Unable to obtain list of tables from data source. The trouble shooting help says that data source may be busy. However when using Word 97, mail merge works fine. In Word I can see that the file type for the Outlook file is *.olk. However Pulisher does not appear to recognize this file type, scanned Open Data source file types. Does anyone know how to resolve this? Thanks, Rick ...