T
Tim Cadieux
I've got a Template to which I add a routing slip when the client hits the
Submit button. I also send a separate e-mail to one group because their
Service account will read the e-mail and add the job directly into their
work database. This Template works perfectly fine on my Machine but on a
number of other PCs, it simply shuts down when it hits the first Route
Recipient e-mail address¦
I've pasted the code belowI have a reference to Outlook 9.0 Object Library
Sub SendEnvoyer()
Static Sent As Integer
If Sent = 1 Then
MsgBox "The document has already been sent / Le document est envoyer."
Else
Call SendAsRoutingSlip
Call SendtoTrinetSolutions
MsgBox "Document sent/envoyer"
End If
Sent = 1
End Sub
Sub SendAsRoutingSlip()
With ActiveDocument
.HasRoutingSlip = True
.RoutingSlip.AddRecipient Recipient:="Services - Security
Operations/operations securite" <-- Word Simply Closes right here
.RoutingSlip.AddRecipient Recipient:="Human Res./Res. Humaines"
.RoutingSlip.AddRecipient Recipient:="Orientation Employee/employees"
.RoutingSlip.AddRecipient Recipient:="Services - Accounting
Services/Services de comptabilitiÉ"
.RoutingSlip.AddRecipient Recipient:="Services - CIMS Support/Soutien
CIMS"
.RoutingSlip.AddRecipient Recipient:="Services - Facilities/Locaux"
.RoutingSlip.AddRecipient Recipient:="Services - Library/BibliothÈque"
.RoutingSlip.AddRecipient Recipient:="Services - Mail/Courrier"
.RoutingSlip.AddRecipient Recipient:="Services - Electronic Information
Holdings/Fonds de renseignements Électroniques"
.RoutingSlip.AddRecipient Recipient:="Services - Telecommunications"
.RoutingSlip.AddRecipient Recipient:="Services - Signing Authority /
Pouvoir de signer"
.RoutingSlip.AddRecipient Recipient:="Services - Corporate Reporting
(BI)/Rapports MinistÉriels (IA)"
With .RoutingSlip
.Protect = wdAllowOnlyRevisions
.Subject = "EMPLOYEE ARRIVAL FORM - FORMULAIRE DE L'EMPLOYÉ "
.Message = ""
.Delivery = wdAllAtOnce
.ReturnWhenDone = False
.TrackStatus = False
End With
.Route
End With
End Sub
Sub SendtoTrinetSolutions()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim sContent As String
Dim Lang As String, Dept As String
'Get the Document's information and store it in 1 Variable
If ActiveDocument.FormFields("check6").Result = 1 Then 'check box is
checked
Lang = "English"
ElseIf ActiveDocument.FormFields("check5").Result = 1 Then
Lang = "French"
End If
If ActiveDocument.FormFields("check7").Result = 1 Then 'check box is
checked
Dept = "Fin"
ElseIf ActiveDocument.FormFields("check8").Result = 1 Then
Dept = "TBS-SCT"
ElseIf ActiveDocument.FormFields("check9").Result = 1 Then
Dept = "PSHRMAC/AGRHFPC"
End If
sContent = "Start Date: " & (ActiveDocument.FormFields("Text24").Result) &
vbCrLf
sContent = sContent & "Last Name: " &
(ActiveDocument.FormFields("Text1").Result) & vbCrLf
sContent = sContent & "First Name: " &
(ActiveDocument.FormFields("Text15").Result) & vbCrLf
sContent = sContent & "Middle Initial: " &
(ActiveDocument.FormFields("initial").Result) & vbCrLf
sContent = sContent & "Department: " & Dept & vbCrLf
sContent = sContent & "Language: " & Lang & vbCrLf
sContent = sContent & "Branch: " &
(ActiveDocument.FormFields("Text18").Result) & vbCrLf
sContent = sContent & "Division: " &
(ActiveDocument.FormFields("Text19").Result) & vbCrLf
sContent = sContent & "Section: " &
(ActiveDocument.FormFields("Text20").Result) & vbCrLf
sContent = sContent & "Reports To: " &
(ActiveDocument.FormFields("Text23").Result) & vbCrLf
If ActiveDocument.FormFields("Text27").Result <> "" Then
sContent = sContent & "Previous Department : " &
(ActiveDocument.FormFields("Text27").Result) & vbCrLf
End If
sContent = sContent & "Comments : " &
(ActiveDocument.FormFields("Text34").Result) & vbCrLf
On Error Resume Next
'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
'Set the recipient for the new email
.To = "Services - Trinet Solutions"
'Set the recipient for a copy
'.CC = "(e-mail address removed)"
'Set the subject
.Subject = "EMPLOYEE ARRIVAL FORM - FORMULAIRE DE L'EMPLOYÉ"
'The content of the document is used as the body for the email
.Body = sContent
.Send
End With
If bStarted Then
'If we started Outlook from code, then close it
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub
Submit button. I also send a separate e-mail to one group because their
Service account will read the e-mail and add the job directly into their
work database. This Template works perfectly fine on my Machine but on a
number of other PCs, it simply shuts down when it hits the first Route
Recipient e-mail address¦
I've pasted the code belowI have a reference to Outlook 9.0 Object Library
Sub SendEnvoyer()
Static Sent As Integer
If Sent = 1 Then
MsgBox "The document has already been sent / Le document est envoyer."
Else
Call SendAsRoutingSlip
Call SendtoTrinetSolutions
MsgBox "Document sent/envoyer"
End If
Sent = 1
End Sub
Sub SendAsRoutingSlip()
With ActiveDocument
.HasRoutingSlip = True
.RoutingSlip.AddRecipient Recipient:="Services - Security
Operations/operations securite" <-- Word Simply Closes right here
.RoutingSlip.AddRecipient Recipient:="Human Res./Res. Humaines"
.RoutingSlip.AddRecipient Recipient:="Orientation Employee/employees"
.RoutingSlip.AddRecipient Recipient:="Services - Accounting
Services/Services de comptabilitiÉ"
.RoutingSlip.AddRecipient Recipient:="Services - CIMS Support/Soutien
CIMS"
.RoutingSlip.AddRecipient Recipient:="Services - Facilities/Locaux"
.RoutingSlip.AddRecipient Recipient:="Services - Library/BibliothÈque"
.RoutingSlip.AddRecipient Recipient:="Services - Mail/Courrier"
.RoutingSlip.AddRecipient Recipient:="Services - Electronic Information
Holdings/Fonds de renseignements Électroniques"
.RoutingSlip.AddRecipient Recipient:="Services - Telecommunications"
.RoutingSlip.AddRecipient Recipient:="Services - Signing Authority /
Pouvoir de signer"
.RoutingSlip.AddRecipient Recipient:="Services - Corporate Reporting
(BI)/Rapports MinistÉriels (IA)"
With .RoutingSlip
.Protect = wdAllowOnlyRevisions
.Subject = "EMPLOYEE ARRIVAL FORM - FORMULAIRE DE L'EMPLOYÉ "
.Message = ""
.Delivery = wdAllAtOnce
.ReturnWhenDone = False
.TrackStatus = False
End With
.Route
End With
End Sub
Sub SendtoTrinetSolutions()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim sContent As String
Dim Lang As String, Dept As String
'Get the Document's information and store it in 1 Variable
If ActiveDocument.FormFields("check6").Result = 1 Then 'check box is
checked
Lang = "English"
ElseIf ActiveDocument.FormFields("check5").Result = 1 Then
Lang = "French"
End If
If ActiveDocument.FormFields("check7").Result = 1 Then 'check box is
checked
Dept = "Fin"
ElseIf ActiveDocument.FormFields("check8").Result = 1 Then
Dept = "TBS-SCT"
ElseIf ActiveDocument.FormFields("check9").Result = 1 Then
Dept = "PSHRMAC/AGRHFPC"
End If
sContent = "Start Date: " & (ActiveDocument.FormFields("Text24").Result) &
vbCrLf
sContent = sContent & "Last Name: " &
(ActiveDocument.FormFields("Text1").Result) & vbCrLf
sContent = sContent & "First Name: " &
(ActiveDocument.FormFields("Text15").Result) & vbCrLf
sContent = sContent & "Middle Initial: " &
(ActiveDocument.FormFields("initial").Result) & vbCrLf
sContent = sContent & "Department: " & Dept & vbCrLf
sContent = sContent & "Language: " & Lang & vbCrLf
sContent = sContent & "Branch: " &
(ActiveDocument.FormFields("Text18").Result) & vbCrLf
sContent = sContent & "Division: " &
(ActiveDocument.FormFields("Text19").Result) & vbCrLf
sContent = sContent & "Section: " &
(ActiveDocument.FormFields("Text20").Result) & vbCrLf
sContent = sContent & "Reports To: " &
(ActiveDocument.FormFields("Text23").Result) & vbCrLf
If ActiveDocument.FormFields("Text27").Result <> "" Then
sContent = sContent & "Previous Department : " &
(ActiveDocument.FormFields("Text27").Result) & vbCrLf
End If
sContent = sContent & "Comments : " &
(ActiveDocument.FormFields("Text34").Result) & vbCrLf
On Error Resume Next
'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
'Set the recipient for the new email
.To = "Services - Trinet Solutions"
'Set the recipient for a copy
'.CC = "(e-mail address removed)"
'Set the subject
.Subject = "EMPLOYEE ARRIVAL FORM - FORMULAIRE DE L'EMPLOYÉ"
'The content of the document is used as the body for the email
.Body = sContent
.Send
End With
If bStarted Then
'If we started Outlook from code, then close it
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub