I guess my terminology is confusing.
By batch file I don't mean a .bat file. The batch file contains the data required to produce the documents including a DocumentID which determines which template will be used.
Each template has macros as follows:
Option Explicit
'General Variables
Dim lFileCount As Long
Dim sRequest As String
Private Const ORIGINAL As Integer = 1
Private Const COPY As Integer = 2
Public bAgentStatus As Boolean
Dim iNoOfDocCounter As Integer
Public Sub LoadTemplates(colDf As Collection)
On Error GoTo ErrorHandler
setCollection colData:=colDf
sRequest = Find_Field("PrintJob", "REQUESTID", 1)
bAgentStatus = GetAgentStatus()
LoadClientDocs
' Add Agent Copies
If bAgentStatus Then
LoadAgentDocs
End If
Finish:
Exit Sub
ErrorHandler:
ErrorRoutine ("SSIA_Maturity_Statement_Pack::LoadTemplates")
End Sub
Public Sub LoadClientDocs()
On Error GoTo ErrorHandler
lFileCount = 0
'Call & Build Client Statement (Covering Letter included)
BuildTemplate "SSIA_Maturity_Statement_Client_Covering_Letter.dot ", ORIGINAL, lFileCount, sRequest
BuildTemplate "SSIA_Maturity_Statement.dot ", ORIGINAL, lFileCount, sRequest
LoadSubDocuments sRequestID:=sRequest, lFiles:=lFileCount
Call RemoveBlankFirstPage
iNoOfDocCounter = iNoOfDocCounter + 1
CreateOMRDetails colDf:=objClass, iNoOfDocCounter:=iNoOfDocCounter, _
bFeederOne:=False, bDuplex:=False
Finish:
Exit Sub
ErrorHandler:
ErrorRoutine ("SSIA_Maturity_Statement_Pack::LoadClientDocs")
End Sub
Public Sub LoadAgentDocs()
On Error GoTo ErrorHandler
lFileCount = 0
BuildTemplate "SSIA_Maturity_Statement_Agent_Covering_Letter.dot", ORIGINAL, lFileCount, sRequest
BuildTemplate "SSIA_Maturity_Statement_Client_Covering_Letter.dot", COPY, lFileCount, sRequest
BuildTemplate "SSIA_Maturity_Statement.dot", COPY, lFileCount, sRequest
LoadSubDocuments sRequestID:=sRequest, lFiles:=lFileCount
iNoOfDocCounter = iNoOfDocCounter + 1
CreateOMRDetails colDf:=objClass, iNoOfDocCounter:=iNoOfDocCounter, _
bFeederOne:=False, bDuplex:=False
Finish:
Exit Sub
ErrorHandler:
ErrorRoutine ("SSIA_Maturity_Statement_Pack::LoadAgentDocs")
End Sub
In the vb application the templates are loaded as follows:
Private Sub Build_Document()
On Error GoTo ErrorHandler
Dim lErrCount As Long
' Add the template to the Existing Word object
objWordApp.Documents.Add Template:=g_objDocServerDetails.GetTemplateFileName
objWordApp.Documents(1).Activate
objWordApp.Documents(1).VBProject.VBComponents(1).Activate
' Add the Universal Template
objWordApp.AddIns.Add FileName:="GenTemp.dot", Install:=True
If IsAnnualStatement Or IsTransactionStatement Then
objWordApp.AddIns.Add FileName:="GeneralAnnTrans.dot", Install:=True
End If
If g_objDocServerDetails.GetEventFlag <> 9 Then
'Set these values here, as they are sometimes changed in templates
sOriginal = UCase(colDataFile.Item("PrintDetails;1").Item("Original"))
If Val(Find_Field("PrintDetails", "ClientCopies", 1)) > 0 Then
sCopy = "CLIENT"
ElseIf Val(Find_Field("PrintDetails", "AgentCopies", 1)) > 0 Then
sCopy = "AGENT"
End If
End If
objWordApp.ActiveDocument.LoadTemplates colDf:=colDataFile
Finish:
Exit Sub
ErrorHandler:
If Err.Number = ERR_WORDAUTOMATION Or Err.Number = ERR_WORDAUTOMATION2 _
Or Err.Number = ERR_AUTOMATION Then
Call gObjErrorHandler.WriteLog("Word automation warning in frmDocServer::Build_Document, " & _
"restarting the word process: Err.No-" & Err.Number & _
", Err.Desc-" & Err.Description)
Call KillWordProcesses
Call CreateWordObject
Resume
Else
Call ErrorRoutine("frmDocServer::Build_Document, the error is " & Err.Description)
End If
End Sub