Outlook - Different Versions

  • Thread starter Thread starter Sophie
  • Start date Start date
S

Sophie

Hello Everyone!

I'm sending out a spreadsheet with some code which people
will run to email me back. Sometimes it crashes because
everyone out there has a different version of Outlook.

I've had a good look through the postings on here and
think it's because the reference files are different.
I've got a found function that will tell me what version
everyone out there is using. But I don't know what to do
then?

I think it's one of the posts but it's just too
complicated for me, I'm new to VB.

My code is below.

If anyone could help I'd be very grateful

Sxx

Sub SimpleSender()

CheckOLVersion

MsgBox CheckOLVersion

Dim objOutlook As New Outlook.Application
Dim objOutlookMsg As Outlook.MailItem


'Open Outlook
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg

.Display
.Recipients.Add "Sophie"
.subject = "Tester"
.Body = "Here I am"
'.Send

End With

Set objOutlook = Nothing


End Sub
Function CheckOLVersion() ' As String
Dim objOL ' As Outlook.Application
Dim strVersion ' As String
Dim arrVer
On Error Resume Next

Set objOL = CreateObject("Outlook.Application")
strVersion = objOL.Version
If Err Then
' Outlook 97
CheckOLVersion = "97"
Exit Function
End If

arrVer = Split(strVersion, ".")
Select Case CInt(arrVer(0))
Case 8 ' Outlook 98
CheckOLVersion = "98"
Case 9 ' Outlook 2000
CheckOLVersion = "2000"
Case 10 ' Outlook 2002
CheckOLVersion = "2002"
Case 11 ' Outlook 2003
CheckOLVersion = "2003"
End Select
Set objOL = Nothing
End Function
 
Hi Dick

My code now look like this. Worked fine on my machine but
when testing it with a friend they told me it was a
mixture of early and late binding! Would you mind helping
again? Also in my OL version code I use

arrVer = Split(strVersion, ".")

Apparently this doesn't work for XL 97, can I use
something else?

Thank you

S

Sub SimpleSender()

'CheckOLVersion

'MsgBox CheckOLVersion

Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")

Dim objOutlookMsg As Outlook.MailItem

'Open Outlook
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg

.Display
.Recipients.Add "sophie"
.subject = "Believe it or not ........"
.Body = "This works"
.Send

End With

Set objOutlook = Nothing


End Sub
 
S
My code now look like this. Worked fine on my machine but
when testing it with a friend they told me it was a
mixture of early and late binding! Would you mind helping
again? Also in my OL version code I use

arrVer = Split(strVersion, ".")

Apparently this doesn't work for XL 97, can I use
something else?

Tell them to upgrade. Just kidding, use this function instead

http://www.dicks-blog.com/excel/2004/05/split97.html

See inline below
Sub SimpleSender()

'CheckOLVersion

'MsgBox CheckOLVersion

Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")

Dim objOutlookMsg As Outlook.MailItem

No variables should be dimmed as Outlook.Anything. All Outlook variables
need to be dimmed as Object
'Open Outlook
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

olMailItem is a constant that resides in the Outlook Library. When your
code compiles, it doesn't know about that library yet, so you have to use
the constant's intrinsic value.

objOutlook.CreateItem(0)

zero is the intrinsic value for that constant. To find these values, use
the Immediate Window (with the reference still set)

?olMailItem
0
With objOutlookMsg

.Display
.Recipients.Add "sophie"
.subject = "Believe it or not ........"
.Body = "This works"
.Send

End With

Set objOutlook = Nothing


End Sub

Everything else looks fine. Before you send it, uncheck the Outlook
reference on your machine. Then you can compile and run it and see if you
missed any early-binding stuff.
 
Dick

Fantastic!

Thank you

S
-----Original Message-----
S


Tell them to upgrade. Just kidding, use this function instead

http://www.dicks-blog.com/excel/2004/05/split97.html

See inline below


No variables should be dimmed as Outlook.Anything. All Outlook variables
need to be dimmed as Object

olMailItem is a constant that resides in the Outlook Library. When your
code compiles, it doesn't know about that library yet, so you have to use
the constant's intrinsic value.

objOutlook.CreateItem(0)

zero is the intrinsic value for that constant. To find these values, use
the Immediate Window (with the reference still set)

?olMailItem
0


Everything else looks fine. Before you send it, uncheck the Outlook
reference on your machine. Then you can compile and run it and see if you
missed any early-binding stuff.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top