davidboutche
12-18-2009, 08:51 AM
I'm using the following code to email the active document to another user but when it does this it seems to lose it's code and turns it into a normal word document, not a template. It show the missing refererence to the original file (.doc).
Sub eMailActiveDocument()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(0)
Set Doc = ActiveDocument
Doc.Save
With EmailItem
.Subject = "A Caution Certificate has been issued"
.Body = "A " & ActiveDocument.Bookmarks("appbook").Range.Text & " has been issued to:" & vbCrLf & _
"Surname: " & ActiveDocument.Bookmarks("surnamebook").Range.Text & vbCrLf & _
"First Names: " & ActiveDocument.Bookmarks("forenamebook").Range.Text & vbCrLf & _
"Address: " & ActiveDocument.Bookmarks("addressbook").Range.Text & vbCrLf & _
"Post Code: " & ActiveDocument.Bookmarks("postcodebook").Range.Text & vbCrLf & _
"DOB: " & ActiveDocument.Bookmarks("dobbook").Range.Text & vbCrLf & _
"Sex: " & ActiveDocument.Bookmarks("sexbook").Range.Text & vbCrLf & _
"Age: " & ActiveDocument.Bookmarks("agebook").Range.Text & vbCrLf & _
"Ethnicity: " & ActiveDocument.Bookmarks("ethnicitybook").Range.Text & vbCrLf & _
"Place of Birth: " & ActiveDocument.Bookmarks("pobbook").Range.Text & vbCrLf & _
"Occupation: " & ActiveDocument.Bookmarks("occupationbook").Range.Text & vbCrLf & _
"Custody Number: " & ActiveDocument.Bookmarks("custodybook").Range.Text & vbCrLf & vbCrLf & _
"Offence Details" & vbCrLf & vbCrLf & _
"Offence: " & ActiveDocument.Bookmarks("offencebook").Range.Text & vbCrLf & _
"Time,Date and Location of Offence: " & ActiveDocument.Bookmarks("datebook").Range.Text & _
vbCrLf & "Crime Number: " & ActiveDocument.Bookmarks("crimebook").Range.Text & vbCrLf & _
"Additional Offence: " & ActiveDocument.Bookmarks("secondoffencebook").Range.Text & vbCrLf & _
"Time,Date and Location of second offence: " & _
ActiveDocument.Bookmarks("seconddatebook").Range.Text & vbCrLf & _
"Second Crime Number: " & ActiveDocument.Bookmarks("secondcrimebook").Range.Text & _
vbCrLf & vbCrLf & "Rank: " & ActiveDocument.Bookmarks("adminrankbook").Range.Text & vbCrLf & _
"Collar Number: " & ActiveDocument.Bookmarks("admincollarbook").Range.Text & vbCrLf & _
"Station Code: " & ActiveDocument.Bookmarks("adminstationbook").Range.Text & vbCrLf & _
"Date Administered: " & ActiveDocument.Bookmarks("admindatebook").Range.Text
.To = ".Non Court Disposals"
.Importance = 1 'Or olImprotanceHigh Or olImprotanceLow
' .Attachments.Add Doc.FullName
' .Send
.Display
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
MsgBox ("Non Court Disposals have been notified of the caution being issued. " & _
"If you are asked if you want to allow a program to send messages " & _
"on your behalf click 'yes'")
End Sub
Is there anyway I can adapt this code so it keeps it's template properties? I need to keep the code to ensure the buttons work when the next user gets it.
Thanks
Edited 21-Dec-09 by geekgirlau. Reason: insert line breaks
Sub eMailActiveDocument()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(0)
Set Doc = ActiveDocument
Doc.Save
With EmailItem
.Subject = "A Caution Certificate has been issued"
.Body = "A " & ActiveDocument.Bookmarks("appbook").Range.Text & " has been issued to:" & vbCrLf & _
"Surname: " & ActiveDocument.Bookmarks("surnamebook").Range.Text & vbCrLf & _
"First Names: " & ActiveDocument.Bookmarks("forenamebook").Range.Text & vbCrLf & _
"Address: " & ActiveDocument.Bookmarks("addressbook").Range.Text & vbCrLf & _
"Post Code: " & ActiveDocument.Bookmarks("postcodebook").Range.Text & vbCrLf & _
"DOB: " & ActiveDocument.Bookmarks("dobbook").Range.Text & vbCrLf & _
"Sex: " & ActiveDocument.Bookmarks("sexbook").Range.Text & vbCrLf & _
"Age: " & ActiveDocument.Bookmarks("agebook").Range.Text & vbCrLf & _
"Ethnicity: " & ActiveDocument.Bookmarks("ethnicitybook").Range.Text & vbCrLf & _
"Place of Birth: " & ActiveDocument.Bookmarks("pobbook").Range.Text & vbCrLf & _
"Occupation: " & ActiveDocument.Bookmarks("occupationbook").Range.Text & vbCrLf & _
"Custody Number: " & ActiveDocument.Bookmarks("custodybook").Range.Text & vbCrLf & vbCrLf & _
"Offence Details" & vbCrLf & vbCrLf & _
"Offence: " & ActiveDocument.Bookmarks("offencebook").Range.Text & vbCrLf & _
"Time,Date and Location of Offence: " & ActiveDocument.Bookmarks("datebook").Range.Text & _
vbCrLf & "Crime Number: " & ActiveDocument.Bookmarks("crimebook").Range.Text & vbCrLf & _
"Additional Offence: " & ActiveDocument.Bookmarks("secondoffencebook").Range.Text & vbCrLf & _
"Time,Date and Location of second offence: " & _
ActiveDocument.Bookmarks("seconddatebook").Range.Text & vbCrLf & _
"Second Crime Number: " & ActiveDocument.Bookmarks("secondcrimebook").Range.Text & _
vbCrLf & vbCrLf & "Rank: " & ActiveDocument.Bookmarks("adminrankbook").Range.Text & vbCrLf & _
"Collar Number: " & ActiveDocument.Bookmarks("admincollarbook").Range.Text & vbCrLf & _
"Station Code: " & ActiveDocument.Bookmarks("adminstationbook").Range.Text & vbCrLf & _
"Date Administered: " & ActiveDocument.Bookmarks("admindatebook").Range.Text
.To = ".Non Court Disposals"
.Importance = 1 'Or olImprotanceHigh Or olImprotanceLow
' .Attachments.Add Doc.FullName
' .Send
.Display
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
MsgBox ("Non Court Disposals have been notified of the caution being issued. " & _
"If you are asked if you want to allow a program to send messages " & _
"on your behalf click 'yes'")
End Sub
Is there anyway I can adapt this code so it keeps it's template properties? I need to keep the code to ensure the buttons work when the next user gets it.
Thanks
Edited 21-Dec-09 by geekgirlau. Reason: insert line breaks