VBScript to automatically insert strings into word document, print and close it

VBScript to automatically insert strings into word document, print and close it

Door: Arnout van der Vorst

Make sure you have the file “document.doc” and it contains the bookmarks as you can see (Text1-7). The VBScript will open the document, insert all strings into the bookmarks, print and close it without saving so you can re-use it.

strLocation = wscript.arguments(0)
strLastname = wscript.arguments(1)
strFirstname = wscript.arguments(2)
strDepartment = wscript.arguments(3)
strUserID = wscript.arguments(4)
strPassword = wscript.arguments(5)
strUmraServicePath = wscript.arguments(6)

SourceDocPath = strUmraServicePath & “document.doc”
set ObjWord = CreateObject(“Word.Application”)
RetVal = ObjWord.Documents.Open(SourceDocPath)
ObjWord.Visible = False
ObjWord.ScreenUpdating = False

ObjWord.ActiveDocument.Bookmarks(“Text1”).Select
ObjWord.Selection.Text = strLocation
ObjWord.ActiveDocument.Bookmarks(“Text2”).Select
ObjWord.Selection.Text = strLastName
ObjWord.ActiveDocument.Bookmarks(“Text3”).Select
ObjWord.Selection.Text = strFirstName
ObjWord.ActiveDocument.Bookmarks(“Text4”).Select
ObjWord.Selection.Text = strDepartment
ObjWord.ActiveDocument.Bookmarks(“Text5”).Select
ObjWord.Selection.Text = Now
ObjWord.ActiveDocument.Bookmarks(“Text6”).Select
ObjWord.Selection.Text = strUserID
ObjWord.ActiveDocument.Bookmarks(“Text7”).Select
ObjWord.Selection.Text = strPassword

objWord.ActiveDocument.PrintOut False
objWord.ActiveDocument.Close 0
objWord.Quit
set objWord = Nothing

Geschreven door:
Arnout van der Vorst

Arnout van der Vorst is Identity Management Architect bij Tools4ever en al ruim 10 jaar in dienst. Arnout legt zich als Architect toe op het bedenken en ontwikkelen van nieuwe features, oplossingen en diensten van Tools4ever die aansluiten op de vraag uit de markt. Arnout studeerde Hogere Informatica aan de Hogeschool van Utrecht.

Anderen bekeken ook

SAP koppeling met Active Directory

SAP koppeling met Active Directory

06 september 2012

RBAC: sleutelrol, beheer en evolutie

RBAC: sleutelrol, beheer en evolutie

15 maart 2011

De vooroordelen van Single Sign On

De vooroordelen van Single Sign On

29 november 2011

Single Sign On met terminal emulatie (VAX64, AS/400, Linux, SSH)

Single Sign On met terminal emulatie (VAX64, AS/400, Linux, SSH)

14 oktober 2010

User- en toegangsbeheer in cloud applicaties: een uitdaging

User- en toegangsbeheer in cloud applicaties: een uitdaging

04 september 2012