Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Word Table movement and layout questions 3

Status
Not open for further replies.

tamayok

Programmer
Sep 4, 2001
99
PR
Hi,

I have some basic Word automation questions:

<1> How to obtain the number of cells in a Word table?
<2> How to obtain the number of columns in a Word table?
<3> How to move to the first/leftmost cell of x row in a Word table?

I have come across several good examples on how to CREATE a table in Word from VFP via automation, but did not find the reverse.

Many thanks!

Kenneth Tamayo
San Juan, Puerto Rico - USA
 
Kenet,
The easiest way to learn Aoutomation is:
Open the document you want.
Choose Tools->Macros->Record new macro
Do whaever you want to do
stop recording the macro
Tools->Macros->Open the macro just recorded for editing and try to undersatnd the VB code there.


Borislav Borissov
 

<1> How to obtain the number of cells in a Word table?
<2> How to obtain the number of columns in a Word table?

Code:
o = CREATEOBJECT("word.application")
lodoc=o.Documents.Open("c:\doc1.doc")
?lodoc.Tables.Count
?lodoc.Tables(1).Columns.Count
?lodoc.Tables(1).Rows.Count

<3> How to move to the first/leftmost cell of x row in a Word table?

Don't know. How would you do that in Word itself?



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Mike Gagnon,

Thanks!! These are perfect. My star to you!

I do .Selection.SelectCell followed with .Selection.MoveRight but had no way to find out if I had reached the end of the table's row. Reaching the end of the row by this means rightfully provokes a "OLE Dispatch exception code...".

Manually, one would tab or keypress the down-arrow, followed with a left-arrow...

I imagine there's a way to navigate to a specific cell through automation.

Kenneth Tamayo


 

Manually, one would tab or keypress the down-arrow, followed with a left-arrow...

Sorry I misunderstood your question, I thought you wanted to move the cell itself. Borislav shows you the way to get to a specific cell.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Borislav, a star for you as well...

My deepest appreciation for your help!

Not only is VFP the best tool out there, but the community is always here.

Regards,

Kenneth
 
As I just said in another thread, it's better not to use selection. If you want to affect the contents of a cell, talk to the cell:

loDoc.Tables[1].Cells[1,3].Range.Text = "Blah"

Tamar
 
Thanks Tamar,

I am only copying the contents of the cell but will definitely use your method if I needed to alter its content.

On an un-related subject, I very much regret that apparently I will not be able to make it to the October SouthWest Developers Conference and have a chance to meet you, Craig and others... I sure hope to make it to the next big VFP Conference.

Kenneth Tamayo
San Juan, Puerto Rico - USA
 
Same answer for just reading the contents. Refer to the cell directly:

cValue = loDoc.Tables[1].Cells[1,3].Range.Text

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top