Login   /   Register

Create and save 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 network adapter data from a computer, displays that data in a Microsoft Word document, and then saves the document as C:\Word\Network Adapter Report.doc.

Set word = CreateObject( "Word.Application" )
word.Caption = "Test Caption"
word.Visible = True
 
Set doc = word.Documents.Add()
Set selection = word.Selection
 
With selection
    .Font.Name = "Arial"
    .Font.Size = "18"
    .TypeText "Network Adapter Report"
    .TypeParagraph()
    
    .Font.Size = "14"
    .TypeText "" & Date()
    .TypeParagraph()
    .TypeParagraph()
    .Font.Size = "10"
End With
 
sComputer = "."
Set wmiService = GetObject( "winmgmts:\\" & sComputer & "\root\cimv2" )
Set itemsColl = wmiService.ExecQuery( "Select * from Win32_NetworkAdapterConfiguration" )
 
For Each item in itemsColl
   With selection
      .Font.Bold = True
    .TypeText "ARP Always Source Route: " 
    .Font.Bold = False
    .TypeText "" & item.ArpAlwaysSourceRoute
    .TypeParagraph()
    
    .Font.Bold = True
    .TypeText "ARP Use EtherSNAP: "
    .Font.Bold = False
    .TypeText ""  & item.ArpUseEtherSNAP
    .TypeParagraph()
 
    .Font.Bold = True
    .TypeText "Caption: "
    .Font.Bold = False
    .TypeText ""  & item.Caption
    .TypeParagraph()
 
    .Font.Bold = True
    .TypeText "Database Path: "
    .Font.Bold = False
    .TypeText ""   & item.DatabasePath
    .TypeParagraph()
 
    .Font.Bold = True
    .TypeText "Dead GW Detection Enabled: "
    .Font.Bold = False
    .TypeText ""   & item.DeadGWDetectEnabled
    .TypeParagraph()
 
    .Font.Bold = True
    .TypeText "Default TOS: "
    .Font.Bold = False
    .TypeText ""  & item.DefaultTOS
    .TypeParagraph()
 
    .Font.Bold = True
    .TypeText "Default TTL: "
    .Font.Bold = False
    .TypeText ""  & item.DefaultTTL
    .TypeParagraph()
 
    .Font.Bold = True
    .TypeText "Description: "
    .Font.Bold = True
    .Font.Bold = False
    .TypeText ""  & item.Description
    .TypeParagraph()
    
    .TypeParagraph()
   End With
Next
 
doc.SaveAs( "C:\Word\Network Adapter Report.doc" )
word.Quit

Posted in MS-Word

Leave a Reply

You must be logged in to post a comment.

This article was viewed 311 times