Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Outlook - Different Versions
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Outlook - Different Versions
Sophie
You need to use "late binding" and let VBA determine the correct reference. See here http://www.dicks-clicks.com/excel/olBinding.htm -- Dick Kusleika MVP - Excel Excel Blog - Daily Dose of Excel www.dicks-blog.com "Sophie" wrote in message ... 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Outlook - Different Versions
Thanks Dick
Very clearly expressed!! S -----Original Message----- Sophie You need to use "late binding" and let VBA determine the correct reference. See here http://www.dicks-clicks.com/excel/olBinding.htm -- Dick Kusleika MVP - Excel Excel Blog - Daily Dose of Excel www.dicks-blog.com "Sophie" wrote in message ... 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 . |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Outlook - Different Versions
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 -----Original Message----- Thanks Dick Very clearly expressed!! S -----Original Message----- Sophie You need to use "late binding" and let VBA determine the correct reference. See here http://www.dicks-clicks.com/excel/olBinding.htm -- Dick Kusleika MVP - Excel Excel Blog - Daily Dose of Excel www.dicks-blog.com "Sophie" wrote in message .. . 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 . . |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Outlook - Different Versions
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 Kusleika MVP - Excel Excel Blog - Daily Dose of Excel www.dicks-blog.com |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Outlook - Different Versions
Dick
Fantastic! Thank you S -----Original Message----- 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 Kusleika MVP - Excel Excel Blog - Daily Dose of Excel www.dicks-blog.com . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
custimized outlook today in outlook 2007 | Excel Discussion (Misc queries) | |||
excel open in outlook if outlook is running | Excel Discussion (Misc queries) | |||
Outlook 11 Outlook 10 Object Library Compatibility Issues | Excel Programming | |||
Please include fonts from previous versions ('98) in new versions | Excel Discussion (Misc queries) | |||
Display mail application either in Outlook, or Outlook express | Excel Programming |