Documente Academic
Documente Profesional
Documente Cultură
const END_OF_STORY=6
objWord.Visible = True
objSelection.TypeParagraph()
objDoc.Tables.Add objRange, 1, 2
objSelection.EndKey END_OF_STORY
objSelection.TypeParagraph()
objSelection.TypeParagraph()
http://quicktestprofessional.wordpress.com/category/automating-ms-word/ 5/4/2011
Automating MS Word « Quick test professional Page 2 of 6
objDoc.Tables.Add objRange, 1, 2
objSelection.EndKey END_OF_STORY
objSelection.TypeParagraph()
Example:
Dim objWD
‘ Quit Word
objWD.Quit
http://quicktestprofessional.wordpress.com/category/automating-ms-word/ 5/4/2011
Automating MS Word « Quick test professional Page 3 of 6
You can refer to the Microsoft Word 2000 Visual Basic Reference for a complete listing of Word
methods and properties that can be used within a QuickTest Professional (QTP) script. You can use
these Word object methods within a QTP script to create documents, edit documents, spell check,
etc.For a complete listing of Word object’s methods and properties, refer to MSDN Library – Microsoft
Word Object Model.
Note:
Microsoft Word’s object methods are not part of QuickTest Professional, therefore, they are not
guaranteed to work and are not supported by Mercury Customer Support. Any changes that Microsoft
may make to these methods are not the responsibility of Mercury.
These examples are not part of QuickTest Professional. They are not guaranteed to work and are not
supported by Mercury Customer Support. You are responsible for any and all modifications that may be
required.
The following example uses Word object methods to open a Microsoft Word Document and to use the
Find object (the Find and Replace functionality) to search for the word “apple.”
Example:
Dim wrdApp
Dim wrdDoc
Dim tString, tRange
Dim p, startRange, endRange
Dim searchString
With wrdDoc
For p = 1 To .Paragraphs.Count
startRange = .Paragraphs(p).Range.Start
endRange = .Paragraphs(p).Range.End
Set tRange = .Range(startRange, endRange)
‘ tString = tRange.Text
tRange.Find.Text = searchString
tRange.Find.Execute
If tRange.Find.Found Then
msgbox “Yes! ” & searchString & ” is present”
End If
http://quicktestprofessional.wordpress.com/category/automating-ms-word/ 5/4/2011
Automating MS Word « Quick test professional Page 4 of 6
Next
.Close ‘ close the document
End With
wrdApp.Quit ‘ close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
The following example uses Word object methods to open a Microsoft Word Document and retrieve
paragraphs from it. Then the InStr VBScript method is used to check for the word “apple.”
Example:
Dim wrdApp
Dim wrdDoc
Dim tString, tRange
Dim p, startRange, endRange
Dim searchString
With wrdDoc
For p = 1 To .Paragraphs.Count
startRange = .Paragraphs(p).Range.Start
endRange = .Paragraphs(p).Range.End
Set tRange = .Range(startRange, endRange)
tString = tRange.Text
tString = Left(tString, Len(tString) – 1) ‘exclude the paragraph-mark
If InStr(1, tString, searchString) > 0 Then ‘ check if the text has the content you want
‘ some other processing here
msgbox “Yes! ” & searchString & ” is present”
End If
Next
.Close ‘ close the document
End With
wrdApp.Quit ‘ close the Word application
Set wrdDoc = Nothing
http://quicktestprofessional.wordpress.com/category/automating-ms-word/ 5/4/2011
Automating MS Word « Quick test professional Page 5 of 6
Archives
March 2011
November 2010
November 2008
October 2008
September 2008
June 2008
March 2008
February 2008
Blog Stats
617,432 hits
Archives
March 2011 (1)
November 2010 (1)
November 2008 (4)
October 2008 (1)
September 2008 (2)
June 2008 (1)
March 2008 (4)
February 2008 (44)
Categories
Automated Test Script Creation Process
Automating MS Word
Automating QC
Automation Object Model For QTP
Backward compatability in QTP
Browser Scripts
COM and QTP
compare 2 text files
Descriptive programming
Descriptive Programming and Child Objetcs
http://quicktestprofessional.wordpress.com/category/automating-ms-word/ 5/4/2011
Automating MS Word « Quick test professional Page 6 of 6
Dictonary Object
DotNetFactory
Excel Automation
Extra Topics
Files and Folders
General Standards to be followed in Test scripts
New Features In QTP9.5
QC-OTA
QTP Additional Faqs
QTP Faqs
QTP Naming Convention
QTP Tips and Faqs
Running stored procedures from QTP
Send keyboard keys
Uncategorized
Uninstall a software using QTP
Uninstall a software using vbscript
Update data in a database
VBScript and IE Automation
VBScript Faqs and Useful resources
What’s New in Quick Test Pro 9.0
Whats New in QTP 9.5
XML Scripting
RSS
Entries RSS
Comments RSS
Site info
Quick test professional
Theme: Andreas04 by Andreas Viklund. Blog at WordPress.com.
http://quicktestprofessional.wordpress.com/category/automating-ms-word/ 5/4/2011