davidboutche
07-30-2009, 06:43 AM
I've been using the function from thread http://www.vbaexpress.com/forum/showthread.php?t=27538
The function takes information from bookmarks and inserts them into an email ready to be sent.
It works fine on my machine as I have office 2003 and I have set in the reference library Microsoft Outlook 11 i think.
This also works when using Office 2000 by selecting outlook 9.
The problem is the word application is used on both computers with 2000 and others with 2003.
Is it possible to overcome this problem without usin two different versions of the template?
Option Explicit
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(olMailItem)
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 = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
' .Attachments.Add Doc.FullName
' .Send
.Display
End With
application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub
:help
The function takes information from bookmarks and inserts them into an email ready to be sent.
It works fine on my machine as I have office 2003 and I have set in the reference library Microsoft Outlook 11 i think.
This also works when using Office 2000 by selecting outlook 9.
The problem is the word application is used on both computers with 2000 and others with 2003.
Is it possible to overcome this problem without usin two different versions of the template?
Option Explicit
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(olMailItem)
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 = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
' .Attachments.Add Doc.FullName
' .Send
.Display
End With
application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub
:help