Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word Table Properties
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00460713
Message ID:
00461502
Vues:
13
I use a simple trick told me by Cetin Basoz:
* Insert invisible bookmark  "Table5" into some cell of Table 5 in the document.
********
LOCAL llContinue, loTable,lcBkMarkToFind
#include wdconst.h
lcBkMarkToFind = "Table5"
WITH oWord.activedocument
	IF .Bookmarks.EXISTS(lcBkMarkToFind)   && If bookmark exists
		.Bookmarks(lcBkMarkToFind).SELECT  && Select it
		WITH .APPLICATION.SELECTION
			.Collapse(wdCollapseEnd)    
			IF .INFORMATION(wdWithInTable) && If we're in a table
				llContinue = .T.
			ENDIF
		ENDWITH
		IF llContinue
			loTable = .APPLICATION.SELECTION.TABLES(1)  && Get table reference
			* The trick is that TABLES(1) here actually 
			* refers to the first table in SELECTION, not in the whole document
			* so it is actually pointing to the oWord.ActiveDocument.Table(5)
			* and that's what needed
			*
			* Now do whatever you need with loTable
		ENDIF
	ELSE
		* do whatever
	ENDIF
ENDWITH
I just stripped out and adjusted some code from my app so I hope it is clear what I am doing here.


>Della,
>Assuming that I have a table (nTable) with a bookmark in Cell[1,1], you say that the oBookmarkRange variable is equal to oWord.Tables[nTable].Cell[1,1].Range. Is there a simple way of going from there to a variable oWord.Tables[nTable]? Assuming (as earlier in the thread) that you don't know the table #? I have an app. with a lot of Word automation, including multiple tables, and every so often the client will add a table into the original template, which upsets the table numbering. Since I'm doing some fairly elaborate formatting in the tables I'd really like to get the oWord.Tables(nTable) object in a simple manner.
>
>TIA
>Barbara
>
>
>>I saw your other reply, and Garrett's solution is definitely the faster and cleaner solution! (I was under the impression that you'd be adding to an existing table.)
>>
>>You may run into the similar situations, so I'll explain my answer a bit better. I'm assuming that your bookmark is somewhere in a table's cell, say oWord.Tables[1].Cell[1,1]. When you ask for the Range of the bookmark and set a variable to oBookmarkRange, you get a variable equal to oWord.Tables[1].Cell[1,1].Range. So if you've ensured oBookmarkRange is within a table with oBookmarkRange.Information(wdWithinTable), you know you've got a cell, and you can act on it just like referencing any other cell, and insert text, format, whatever needs to be done, as in oBookMark.InsertAfter("Hello World").
>>
>>Hope this helps!
>>
>> - della
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform