Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual FoxPro
Expertise: Beginner
Feb 8, 2000

Visual FoxPro 6 and Microsoft Word Tables

Question:
How can I make a table in a Microsoft Word document through OLE Automation from VFP? I investigated with the Visual Basic editor and I can't find how to do it. Could you give me more information?

Answer:
You add a table to a Word document by calling the Add() method of the Tables collection of the currently active document:

Function Add(Range As Range, NumRows As Long, NumColumns As Long) As Table
The Add method takes three parameters. The first parameter is a range where the table should be placed. The second parameter is the number of rows in the table. The third parameter is the number of columns in the table.

The Add method returns an object reference to the table so that you can manipulate the table. To insert a table at the current cursor position, you can pass the Range property of the Selection property.

Here is a code sample that opens Word, makes it visible, creates a blank document, adds a table with three rows and two columns, fills in the cells of the table, and then pauses to allow you to see what the document looks like:

loWord = CREATEOBJECT("word.application")
loWord.visible = .T.

loWord.Documents.Add()

loWord.Selection.TypeText("What follows is a 3x2 table.")
loTable = loWord.ActiveDocument.Tables.Add(loWord.Selection.Range,3,2)

loTable.Cell(1,1).Range.Text = "R1C1"
loTable.Cell(1,2).Range.Text = "R1C2"
loTable.Cell(2,1).Range.Text = "R2C1"
loTable.Cell(2,2).Range.Text = "R2C2"
loTable.Cell(3,1).Range.Text = "R3C1"
loTable.Cell(3,2).Range.Text = "R3C2"

MESSAGEBOX("Pause so that you can see what was done")

loWord.Quit()
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date