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

Arnout van der Vorst

Geschreven door:
Arnout van der Vorst

Maak kennis met Arnout van der Vorst, de inspirerende Identity Management Architect bij Tools4ever sinds het jaar 2000. Na zijn studie Hogere Informatica aan de Hogeschool van Utrecht is hij begonnen als Supportmedewerker bij Tools4ever. Daarna heeft Arnout zich opgewerkt tot een sleutelfiguur in het bedrijf.  Zijn bijdragen strekken zich uit van klantondersteuning tot strategische pre-sales activiteiten, en hij deelt zijn kennis via webinars en artikelen.

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