Hi all,

I'd like to print out a little inventory sheet of a PC. My idea is to use word to design the layout of the document and use docvars to print out the content of the corresponding variables.

The content of the word template looks like that:

Asset Tag: {DOCVARIABLE AssetTag \* MERGEFORMAT}
Serial #: {DOCVARIABLE SerialNumber \* MERGEFORMAT}

My code goes here:

 Code:
;=======================================================================================
;	Name	    	: PCInventory.kix
;	Author	  	: SBLAETTL
;	Date		: 14.11.2013
;	Purpose 	: Prints a paper with all relevant data of a redeployable asset
;	Ext. Dependencies :	
;	
;-------------------------------------------------------------------------------
;	Changes:
;	Author		Date
;=========================================================================================
Break on
Dim $Ret
$Ret = SetOption("Explicit", "on")

Dim $objWordApp
Dim $objWordDoc
Dim $objDoc
Dim $Template

$objWordApp = CreateObject("Word.Application")
If @ERROR <> 0
  $ret = MessageBox("unable to start Word on this device, terminating", "Problem with Office")
  Quit
EndIf
$Template = @SCRIPTDIR + "\Asset Tag.dotx"
If Not(Exist($Template))
  $ret = MessageBox("unable to find template " + $Template + ", terminating", "Problem with configuration")
  Quit
EndIf

$ObjWordDoc = $objWordApp.Application.Documents.Add($Template)

Dim $oField
For Each $oField in $objWordDoc.Fields
 ? "Field name :" + $ofield.name
Next

$Ret = $objWordDoc.Variables.item["AssetTag"].Value = "SomeAssetTagInfo"
$Ret = $objWordDoc.Variables.item["SerialNumber"] .Value = "Here goes Serial Number"
$Ret = $objWordDoc.Fields.Update()

$Ret = $objWordApp.Documents(1).SaveAs(@SCRIPTDIR + "\Useless Text.doc")
$Ret = $objWordApp.quit()



Now my problems... My code finds the two fields (it loops twice) but I'm unable to print out the field names :-( Futhermore, I'm also not able to fill the two docvars... I'm stuck...

Thanks once again for your help

Sam


Edited by Sam_B (2013-11-18 10:03 AM)