Login   /   Register

Apply a style to a table in 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, displays that data in a table in Microsoft Word, then formats the data by using a predefined Microsoft Word style

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 )
table.Range.Font.Size = 10
table.Range.Style = "Table Contemporary"
x = 2
 
table.Cell( x, 1 ).Range.Text = "Process Name"
table.Cell( x, 2 ).Range.text = "Process ID"
table.Cell( x, 3 ).Range.text = "Virtual Size"
 
sComputer = "."
Set wmiService = GetObject( "winmgmts:\\" & sComputer & "\root\cimv2" )
Set itemsColl = wmiService.ExecQuery( "Select * from Win32_Process" )
 
For Each item in itemsColl
    If x > 1 Then
        table.Rows.Add()
    End If
    table.Cell( x, 1 ).Range.Text = item.Name
    table.Cell( x, 2 ).Range.text = item.ProcessId
    table.Cell( x, 3 ).Range.text = item.VirtualSize
    x = x + 1
Next

Posted in MS-Word

Leave a Reply

You must be logged in to post a comment.

This article was viewed 259 times