• RSS
  • Facebook
  • Twitter

One Center for all the Testing Need. OneTestingCenter is for all, for all QA, for all Automation. Automation is easy, fun and enriching experience. Happy Learning and Happy Testing!

  • Access to All QA

    At OneTestingCenter, you find lots of books,articles,blogs and detailed guides. Everyone has access to QA. Happy Learning, Happy Testing.

  • Global Trainings

    All the QA/Auotmation trainings are available at OneTestingCenter. QA, Automation, QTP/UFT, Selenium, LoadRunner, QC/ALM, Appium...

  • Automation Learning Fun

    Technology is always evolving. Automation is always challenging. To be frank, Automation is fun, enthusiastic and enrching experience.

     QTP - Working with Word
    '****************************************************
    'Create a New Word Document
    '****************************************************
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add()
    '**************************************************** 

    '****************************************************
    'Create and Save a Word Document
    '****************************************************
    Set objWord = CreateObject("Word.Application")
    objWord.Caption = "QuickTestQTP by GAReddy"
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add()
    Set objSelection = objWord.Selection
    objSelection.Font.Name = "Arial"
    objSelection.Font.Size = "18"
    objSelection.TypeText "GAReddy @ QTP - Demonstrating Word Creation and Saving"
    objSelection.TypeParagraph()
    objSelection.Font.Size = "14"
    objSelection.TypeText "" & Date()
    objSelection.TypeParagraph()
    objSelection.TypeParagraph()
     objSelection.Font.Size = "10"
        objSelection.Font.Bold = True
        objSelection.TypeText "This is a sample text "
     objSelection.Font.Bold = True
        objSelection.TypeText "Http://QuickTestQTP.blogpsot.com"
        objSelection.Font.Bold = False
        objSelection.TypeText "Hey, this is GAReddy @ QuickTestQTP"
        objSelection.TypeParagraph()
        objSelection.Font.Bold = True
        objSelection.TypeText "Welcome to QuickTestQTP @ Http://QuickTestQTP.blogpsot.com "
        objSelection.Font.Bold = False
        objSelection.TypeText "GARreddy@QuickTestQTP"
        objSelection.TypeParagraph()
    objDoc.SaveAs("C:\MyDoc.doc")
    objWord.Quit
    Set objWord=Nothing

    '****************************************************
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add()
    Set objRange = objDoc.Range()
    objDoc.Tables.Add objRange,1,3
    Set objTable = objDoc.Tables(1)
    objTable.Range.Font.Size = 10
    objTable.Range.Style = "Table Contemporary"
    x=2
    objTable.Cell(x, 1).Range.Text = "Service Name"
    objTable.Cell(x, 2).Range.text = "Display Name"
    objTable.Cell(x, 3).Range.text = "State"
    strComputer = "."
    Set objWMIService = _
        GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
    For Each objItem in colItems
        If x > 1 Then
            objTable.Rows.Add()
        End If
        objTable.Cell(x, 1).Range.Text = objItem.Name
        objTable.Cell(x, 2).Range.text = objItem.DisplayName
        objTable.Cell(x, 3).Range.text = objItem.State
        x = x + 1
    Next
    objDoc.SaveAs("C:\ProcessList2.doc")
    objWord.Quit
    Set objWord=Nothing
     '************************************************************************************
     Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add()
    Set objRange = objDoc.Range()
    objDoc.Tables.Add objRange,1,4,1 ' 4 is no of columns on a table and 1 is the table visbile mode or else 0
    Set objTable = objDoc.Tables(1)
    x=1
    strComputer = "."
    Set objWMIService = _
        GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
    For Each objItem in colItems
        If x > 1 Then
            objTable.Rows.Add()
        End If
        objTable.Cell(x, 1).Range.Font.Bold = True
        objTable.Cell(x, 1).Range.Text = objItem.Name
        objTable.Cell(x, 2).Range.text = objItem.DisplayName
        objTable.Cell(x, 3).Range.text = objItem.State
        x = x + 1
    Next

    objDoc.SaveAs("C:\ProcessList1.doc")
    objWord.Quit
    Set objWord=Nothing

    '========
    '****************************************************
    'Display Service Information in a Word Document
    '****************************************************
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add()
    Set objSelection = objWord.Selection
    objSelection.TypeText "Services Report"
    objSelection.TypeParagraph()
    objSelection.TypeText "" & Now
    objSelection.TypeParagraph()
    objSelection.TypeParagraph()
    strComputer = "."
    Set objWMIService = _
        GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
    For Each objItem in colItems
        objSelection.TypeText objItem.DisplayName & " -- " & objItem.State
        objSelection.TypeParagraph()
    Next
    objDoc.SaveAs("C:\ProcessList.doc")
    objWord.Quit
    Set objWord=Nothing
    '****************************************************

    '****************************************************
    ' Adding Formatted Text to  Word Document
    '****************************************************
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add()
    Set objSelection = objWord.Selection
    objSelection.Font.Name = "Arial"
    objSelection.Font.Size = "18"
    objSelection.TypeText "GAReddy @ QuickTest QTP"
    objSelection.TypeText "Http://QuickTestQTP.blogpsot.com"
    objSelection.TypeParagraph()
    objSelection.Font.Size = "14"
    objSelection.TypeText "" & Date()
    objSelection.TypeParagraph()
    objSelection.Font.Name = "Caliber"
    objSelection.Font.Size = "28"
    objSelection.TypeText " QuickTest QTP > Let's learn adding formated text to Word doc"
    objSelection.TypeText "Http://QuickTestQTP.blogpsot.com"
    objSelection.TypeParagraph()
    objSelection.Font.Size = "14"
    objSelection.TypeText "" & Date()
    objSelection.TypeParagraph()

    '****************************************************

    '****************************************************
    ' Adding Formatted Table to  Word Document
    '****************************************************
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add()
    Set objRange = objDoc.Range()
    objDoc.Tables.Add objRange,1,3
    Set objTable = objDoc.Tables(1)
    x=1
    strComputer = "."
    Set objWMIService = _
        GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
    For Each objItem in colItems
        If x > 1 Then
            objTable.Rows.Add()
        End If
        objTable.Cell(x, 1).Range.Font.Bold = True
        objTable.Cell(x, 1).Range.Text = objItem.Name
        objTable.Cell(x, 2).Range.text = objItem.DisplayName
        objTable.Cell(x, 3).Range.text = objItem.State
        x = x + 1
    Next
    '****************************************************

    Reactions:

    QTP - Microsoft Office - Word

     QTP - Working with Word
    '****************************************************
    'Create a New Word Document
    '****************************************************
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add()
    '**************************************************** 

    '****************************************************
    'Create and Save a Word Document
    '****************************************************
    Set objWord = CreateObject("Word.Application")
    objWord.Caption = "QuickTestQTP by GAReddy"
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add()
    Set objSelection = objWord.Selection
    objSelection.Font.Name = "Arial"
    objSelection.Font.Size = "18"
    objSelection.TypeText "GAReddy @ QTP - Demonstrating Word Creation and Saving"
    objSelection.TypeParagraph()
    objSelection.Font.Size = "14"
    objSelection.TypeText "" & Date()
    objSelection.TypeParagraph()
    objSelection.TypeParagraph()
     objSelection.Font.Size = "10"
        objSelection.Font.Bold = True
        objSelection.TypeText "This is a sample text "
     objSelection.Font.Bold = True
        objSelection.TypeText "Http://QuickTestQTP.blogpsot.com"
        objSelection.Font.Bold = False
        objSelection.TypeText "Hey, this is GAReddy @ QuickTestQTP"
        objSelection.TypeParagraph()
        objSelection.Font.Bold = True
        objSelection.TypeText "Welcome to QuickTestQTP @ Http://QuickTestQTP.blogpsot.com "
        objSelection.Font.Bold = False
        objSelection.TypeText "GARreddy@QuickTestQTP"
        objSelection.TypeParagraph()
    objDoc.SaveAs("C:\MyDoc.doc")
    objWord.Quit
    Set objWord=Nothing

    '****************************************************
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add()
    Set objRange = objDoc.Range()
    objDoc.Tables.Add objRange,1,3
    Set objTable = objDoc.Tables(1)
    objTable.Range.Font.Size = 10
    objTable.Range.Style = "Table Contemporary"
    x=2
    objTable.Cell(x, 1).Range.Text = "Service Name"
    objTable.Cell(x, 2).Range.text = "Display Name"
    objTable.Cell(x, 3).Range.text = "State"
    strComputer = "."
    Set objWMIService = _
        GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
    For Each objItem in colItems
        If x > 1 Then
            objTable.Rows.Add()
        End If
        objTable.Cell(x, 1).Range.Text = objItem.Name
        objTable.Cell(x, 2).Range.text = objItem.DisplayName
        objTable.Cell(x, 3).Range.text = objItem.State
        x = x + 1
    Next
    objDoc.SaveAs("C:\ProcessList2.doc")
    objWord.Quit
    Set objWord=Nothing
     '************************************************************************************
     Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add()
    Set objRange = objDoc.Range()
    objDoc.Tables.Add objRange,1,4,1 ' 4 is no of columns on a table and 1 is the table visbile mode or else 0
    Set objTable = objDoc.Tables(1)
    x=1
    strComputer = "."
    Set objWMIService = _
        GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
    For Each objItem in colItems
        If x > 1 Then
            objTable.Rows.Add()
        End If
        objTable.Cell(x, 1).Range.Font.Bold = True
        objTable.Cell(x, 1).Range.Text = objItem.Name
        objTable.Cell(x, 2).Range.text = objItem.DisplayName
        objTable.Cell(x, 3).Range.text = objItem.State
        x = x + 1
    Next

    objDoc.SaveAs("C:\ProcessList1.doc")
    objWord.Quit
    Set objWord=Nothing

    '========
    '****************************************************
    'Display Service Information in a Word Document
    '****************************************************
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add()
    Set objSelection = objWord.Selection
    objSelection.TypeText "Services Report"
    objSelection.TypeParagraph()
    objSelection.TypeText "" & Now
    objSelection.TypeParagraph()
    objSelection.TypeParagraph()
    strComputer = "."
    Set objWMIService = _
        GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
    For Each objItem in colItems
        objSelection.TypeText objItem.DisplayName & " -- " & objItem.State
        objSelection.TypeParagraph()
    Next
    objDoc.SaveAs("C:\ProcessList.doc")
    objWord.Quit
    Set objWord=Nothing
    '****************************************************

    '****************************************************
    ' Adding Formatted Text to  Word Document
    '****************************************************
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add()
    Set objSelection = objWord.Selection
    objSelection.Font.Name = "Arial"
    objSelection.Font.Size = "18"
    objSelection.TypeText "GAReddy @ QuickTest QTP"
    objSelection.TypeText "Http://QuickTestQTP.blogpsot.com"
    objSelection.TypeParagraph()
    objSelection.Font.Size = "14"
    objSelection.TypeText "" & Date()
    objSelection.TypeParagraph()
    objSelection.Font.Name = "Caliber"
    objSelection.Font.Size = "28"
    objSelection.TypeText " QuickTest QTP > Let's learn adding formated text to Word doc"
    objSelection.TypeText "Http://QuickTestQTP.blogpsot.com"
    objSelection.TypeParagraph()
    objSelection.Font.Size = "14"
    objSelection.TypeText "" & Date()
    objSelection.TypeParagraph()

    '****************************************************

    '****************************************************
    ' Adding Formatted Table to  Word Document
    '****************************************************
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add()
    Set objRange = objDoc.Range()
    objDoc.Tables.Add objRange,1,3
    Set objTable = objDoc.Tables(1)
    x=1
    strComputer = "."
    Set objWMIService = _
        GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
    For Each objItem in colItems
        If x > 1 Then
            objTable.Rows.Add()
        End If
        objTable.Cell(x, 1).Range.Font.Bold = True
        objTable.Cell(x, 1).Range.Text = objItem.Name
        objTable.Cell(x, 2).Range.text = objItem.DisplayName
        objTable.Cell(x, 3).Range.text = objItem.State
        x = x + 1
    Next
    '****************************************************