Set the Word Application variable:
Set appWord = GetObject(, “Word.Application”)
appWord.Visible = True
Get User Templates and Documents paths from the user’s selections on the main menu, using two
functions that pick up the saved paths from tblInfo:
strTemplatePath = GetTemplatesPath
Debug.Print “Template path: “ & strTemplatePath
strDocsPath = GetDocumentsPath
Debug.Print “Documents folder: “ & strDocsPath
strTemplate = “Avery 5164 Shipping Labels.dotx”
strTemplateNameAndPath = strTemplatePath & strTemplate
Debug.Print “Template name and path: “ _
& strTemplateNameAndPath
On Error Resume Next
Look for the template in the templates folder, by attempting to set a FileSystemObject File variable
to it:
Set fil = fso.GetFile(strTemplateNameAndPath)
If fil Is Nothing Then
strPrompt = “Can’t find “ & strTemplate & “ in “ _
& strTemplatePath & “; canceling”
MsgBox strPrompt, vbCritical + vbOKOnly
GoTo ErrorHandlerExit
End If
On Error GoTo ErrorHandler
Calculate the number of sets of labels to print:
lngSelected = Nz(DCount(“*”, _
“qrySelectedNorthwindShippingLabels”))
Me![lblSetsToPrint].Caption = lngSelected _
& “ sets of shipping labels to print”
Exit with a message if no orders have been selected:
If lngSelected = 0 Then
strTitle = “Can’t print labels”
strPrompt = “No orders selected; please mark some “ _
& “orders for shipping”
MsgBox strPrompt, vbExclamation + vbOKOnly, strTitle
GoTo ErrorHandlerExit
End If
Part II Writing VBA Code to Exchange Data between Office Components