Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'Use GetObject
'GetObject([pathname] [, class])
#Const blnWordDebug = True
#if blnWordDebug then
Dim objWord As Word.Application
Dim objDoc As Word.Document
#Else ' Release Version
Dim objWord As object ' Avoid specific WORD version
Dim objDoc As object
#End if
Set objWord = GetObject(,"Word.Application")
Set objDoc = objWord.Documents.Open(strDocumentFile,ReadOnly:=True)
or
Set objDoc = GetObject(strDocummentFile)
Set objWord = objDoc.Application
'Call a Procedure in VBA code under ThisDocument in Word
Dim strVars(1) as string
strVar0) = "My Name"
strVar(1) = "My Addr"
'etc.
objDoc.PrintDoc strVars()
objDoc.Close false ' Do not save changes
objWord.Quit false ' do not save changes
Set objDoc = Nothing
Set objWord = Nothing
'=======================
' Set up Document with DocVariables in proper location
' Use Insert / Filed /Document Automation / Documment Variable - fill in e.g. DOCVARIABLE "Name"
' Use ALT+F9 to toggle fields display on and off or
' right-click on a filed and toggle invidulally.
' Use MSDN.MICROSOFT.COM documentation.
'Put this in a module in Word under ThisDocument Alt+F11 to get to VBA editor
Public Sub PrintDOC(strVars() as string)
SetDocVariable "Name", strVars(0)
SetDocVariable "Address", strVars(1)
'etc.
UpdateFieldsAndPrintDocument
End Sub
Public Sub SetDocVariable(ByVal strVariableName As String, _
ByVal strValue As String)
Dim strDescription As String, _
strWValue As String
If Len(strValue) = 0 Then
strWValue = Space(1) ' Can not be zero length string
Else
strWValue = strValue
End If
'*****
'* Place the value into the indicated Variable.
'* Variables is a "Collection".
'*****
On Error Resume Next
ActiveDocument.Variables(strVariableName) = strWValue
strDescription = Err.Description
On Error GoTo 0
If Len(strDescription) > 0 Then
strDescription = strDescription & vbCrLf & _
"DocVariable=" & strVariableName & " not defined."
MsgBox strDescription
ActiveDocument.Variables.Add strVariableName, _
strWValue
End If
End Sub
Public Sub UpdateFieldsAndPrintDocument(Optional strCopies = "3")
'*****
'* Update fields with DOCVARIABLES
'*****
Dim lngIndex As Long, _
strDescription As String
With ActiveDocument.Fields
lngIndex = .Update
If lngIndex > 0 Then
strDescription = .Item(lngIndex).Code.Text & vbCrLf & _
"Fields Update error"
MsgBox strDescription, vbInformation, _
ActiveDocument.Name
End If
End With
'*****
'* Print Document
'*****
Application.PrintOut FileName:="", _
Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, _
Copies:=strCopies, _
Pages:="", _
PageType:=wdPrintAllPages, _
Collate:=True, _
Background:=False, _
PrintToFile:=False
End Sub