Quick test professional

QTP Tips QTP codes QTP Faqs and more

How to create tables in Microsoft word

How to create tables in Microsoft word 
Set objWord = CreateObject("Word.Application")
const END_OF_STORY=6
objWord.Visible = True
 
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
 
objSelection.TypeText "Table 1"
objSelection.TypeParagraph()
 
Set objRange = objSelection.Range
objDoc.Tables.Add objRange, 1, 2
Set objTable = objDoc.Tables(1)
 
objTable.Cell(1, 1).Range.Text = "This is cell 1."
objTable.Cell(1, 2).Range.Text = "This is cell 2."
objSelection.EndKey END_OF_STORY
objSelection.TypeParagraph()
 
objSelection.TypeText "Table 2"
objSelection.TypeParagraph()
 
Set objRange = objSelection.Range
objDoc.Tables.Add objRange, 1, 2
Set objTable = objDoc.Tables(2)
 
objTable.Cell(1, 1).Range.Text = "This is cell 1."
objTable.Cell(1, 2).Range.Text = "This is cell 2."
 
objSelection.EndKey END_OF_STORY
objSelection.TypeParagraph()
Author: Mohan Kakarla
Advertisements

February 14, 2008 - Posted by | Automating MS Word | , , , , ,

4 Comments »

  1. Thanks for above Word Test…its gr8

    My query:
    I want to fetch MS-Word document Row & Column data and want to insert it in my QTP test.
    –> How would i fetch the Row/Column data from MS-Word document through QTP.
    Please guide and if possible pls give the sample code for it

    Thanks
    Shrinivas

    Comment by Shrinivas | August 4, 2009 | Reply

  2. How to validate the barcode image present on PDF document..

    I am trying to convert the PDF to Word Doc and validate the image from there.. Kindly help me if you have any idea..

    Comment by vij | August 19, 2009 | Reply

  3. Gr8…its working good for me.

    One help.

    (1) Suppose we have a word data as Row in One paragraph, like

    (Paragraph1)
    TCID1, AgentName, Password, OrderNo, FaxNumber, FlightName, CusttomernameX

    (Paragraph2)
    TCIDx, AgentNamex, Passwordx, OrderNox, FaxNumberx,
    FlightNamex, Custtomernamex

    Then how would we get the comma separated data separately and store it in separate variable.

    Please guide

    Thanks
    Shrini

    Comment by Shrini | August 19, 2009 | Reply

  4. How do you connect the database to QTP?

    Thanks

    Comment by Mallinath | December 2, 2009 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: