Login   /   Register

Add a formatted table to a word document

Rate this article
     0 votes, average: 0 out of 50 votes, average: 0 out of 50 votes, average: 0 out of 50 votes, average: 0 out of 50 votes, average: 0 out of 5
Loading ... Loading ...
April 1st, 2008 by daniva

Demonstration script that retrieves service data from a computer and then displays that data in a formatted table in Microsoft Word

Set word = CreateObject( "Word.Application" )
word.Visible = True
Set doc = word.Documents.Add()
 
Set range = doc.Range()
doc.Tables.Add range, 1, 3
Set table = doc.Tables( 1 )
x = 1
 
sComputer = "."
Set wmiService = GetObject( "winmgmts:\\" & sComputer & "\root\cimv2" )
Set itemsColl = wmiService.ExecQuery( "Select * from Win32_Service" )
 
For Each item in itemsColl
    If x > 1 Then
        table.Rows.Add()
    End If
    table.Cell( x, 1 ).Range.Font.Bold = True
    table.Cell( x, 1 ).Range.Text = item.Name
    table.Cell( x, 2 ).Range.text = item.DisplayName
    table.Cell( x, 3 ).Range.text = item.State
    x = x + 1
Next

Posted in MS-Word

Leave a Reply

You must be logged in to post a comment.

This article was viewed 277 times