By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,490 Members | 896 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,490 IT Pros & Developers. It's quick & easy.

reference library missing Microsoft Outlook 9.0 Object Library

P: 4
Hi,

I am trying to run a simple macro in excel vba to create a new email and attach two spreadsheets. But it won't work. It stops at the first line everytime. Dim objOutlook As Outlook.Application

Do I need to install Microsoft Outlook 9.0 Object Library? When I go to Tools-->references I checked off MS outlook 9.0 Object Library. Then it tell me it is missing MS outlook 9.0 Object Library.

Appreciated if someone can give me some insight. I am new at write macros.

Thanks in advance.
Expand|Select|Wrap|Line Numbers
  1. Sub SendMsgwithAttachment()
  2.  
  3. Dim objOutlook As Outlook.Application
  4. Dim objOutlookMsg As Outlook.MailItem
  5. Dim objOutlookRecip As Outlook.Recipent
  6. Dim objOutlookAttach As Outlook.Attachment
  7.  
  8.  
  9. Dim RecipList As String
  10. Dim AttachmentPath As String
  11. Dim SubjectName As String
  12.  
  13. Sheets("Sheet1").Select
  14. RecipList = Range("B1").Value
  15. AttachmentPath = Range("B2").Value
  16. SubjectName = Range("B4").Value
  17. Filename = Range("B6:B7").Value
  18.  
  19.  
  20.  
  21. On Error Resume Next
  22.  
  23. Set objOutlook = CreatObject("Outlook.Application")
  24.  
  25. Set objOutlookMsg = objOutlook.createitem(olmailitem)
  26. With objOutlookMsg
  27.  
  28. Set objOutlookRecip = .Recipients.Add(RecipList)
  29. objOutlookRecip.Type = olTo
  30.  
  31.  
  32. .Subject = SubjectName
  33. .Body = " "
  34.  
  35. If Not IsMissing(AttachmentPath) Then
  36. Set objOutlookAttach = .Attachments.Add(AttachmentPath) & "\" & Array(Filename)
  37. End If
  38.  
  39. For Each objOutkRecip In .Recipients
  40.     objOutlookRecip.Resolve
  41.     If Not objOutlookRecip.Resolve Then
  42. Exit Sub
  43. End If
  44. Next
  45. .Display 'Display the message
  46. End With
  47.  
  48. Set objOutlookMsg = Nothing
  49. Set objOutlook = Nothing
  50.  
  51. End Sub
Sep 11 '07 #1
Share this Question
Share on Google+
9 Replies


P: 68
Try searching for the Microsoft Outlook 9.0 Object Library (MSOUTL.OLB) in windows explorer, to find out if and where it's on your pc. If it's present, go back to Tools-->references and use 'browse' to add the file back in to the library. If it's missing, I'm fairly sure I have in the past simply copied a library file from another PC and referenced it like this.



Hi,

I am trying to run a simple macro in excel vba to create a new email and attach two spreadsheets. But it won't work. It stops at the first line everytime. Dim objOutlook As Outlook.Application

Do I need to install Microsoft Outlook 9.0 Object Library? When I go to Tools-->references I checked off MS outlook 9.0 Object Library. Then it tell me it is missing MS outlook 9.0 Object Library.

Appreciated if someone can give me some insight. I am new at write macros.

Thanks in advance.
Expand|Select|Wrap|Line Numbers
  1. Sub SendMsgwithAttachment()
  2.  
  3. Dim objOutlook As Outlook.Application
  4. Dim objOutlookMsg As Outlook.MailItem
  5. Dim objOutlookRecip As Outlook.Recipent
  6. Dim objOutlookAttach As Outlook.Attachment
  7.  
  8.  
  9. Dim RecipList As String
  10. Dim AttachmentPath As String
  11. Dim SubjectName As String
  12.  
  13. Sheets("Sheet1").Select
  14. RecipList = Range("B1").Value
  15. AttachmentPath = Range("B2").Value
  16. SubjectName = Range("B4").Value
  17. Filename = Range("B6:B7").Value
  18.  
  19.  
  20.  
  21. On Error Resume Next
  22.  
  23. Set objOutlook = CreatObject("Outlook.Application")
  24.  
  25. Set objOutlookMsg = objOutlook.createitem(olmailitem)
  26. With objOutlookMsg
  27.  
  28. Set objOutlookRecip = .Recipients.Add(RecipList)
  29. objOutlookRecip.Type = olTo
  30.  
  31.  
  32. .Subject = SubjectName
  33. .Body = " "
  34.  
  35. If Not IsMissing(AttachmentPath) Then
  36. Set objOutlookAttach = .Attachments.Add(AttachmentPath) & "\" & Array(Filename)
  37. End If
  38.  
  39. For Each objOutkRecip In .Recipients
  40.     objOutlookRecip.Resolve
  41.     If Not objOutlookRecip.Resolve Then
  42. Exit Sub
  43. End If
  44. Next
  45. .Display 'Display the message
  46. End With
  47.  
  48. Set objOutlookMsg = Nothing
  49. Set objOutlook = Nothing
  50.  
  51. End Sub
Sep 12 '07 #2

MMcCarthy
Expert Mod 10K+
P: 14,534
Have a look down the references list and see if there is another version of the library besides 9.0

What version of Office are you using?
Sep 12 '07 #3

P: 4
Have a look down the references list and see if there is another version of the library besides 9.0

What version of Office are you using?
MS 2000
I only have 9.0 right now I found it at the list and check it again. I get a message box when I run the macro.

A program is trying to access email address you have stored in Outlook. Do you want to allow this?

Allow access for 1 min or 10 mins options: Yes, No, Help. I press Yes.

another box appears.

Miscrosoft Excel is waiting for another application to complete an OLE action.

Ok button

what does OLE mean here?

I just keep on getting this message. I can't get a Outlook msg box to appear.
Sep 13 '07 #4

MMcCarthy
Expert Mod 10K+
P: 14,534
Create breakpoint stops in your code. See how far you get before the OLE message appears.
Sep 13 '07 #5

P: 4
Create breakpoint stops in your code. See how far you get before the OLE message appears.

it starts to display OLE message when I get to.

Set objOutlookRecip = .Recipients.Add(RecipList) before

I have the email address saved in a cell in the spreadsheet.

cell A2: joe.bob@yahoo.com ; anne.mary@yahoo.com

then nothing after I just let it make connection with Outlook
Sep 18 '07 #6

MMcCarthy
Expert Mod 10K+
P: 14,534
Have a look at this declaration

Dim objOutlookRecip As Outlook.Recipent

Now change it to

Dim objOutlookRecip As Outlook.Recipients

Does that make a difference
Sep 18 '07 #7

FishVal
Expert 2.5K+
P: 2,653
Hi, CoCoCha.

I think you have faulty code line.
Comment
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
  2.  
and see there does it fail. I suppose you don't want to ignore all errors at this time. ;)

I've run this simplified code in Excel module with no problema.
Expand|Select|Wrap|Line Numbers
  1. Public Sub qqq()
  2.  
  3.     Dim appOutlook As Outlook.Application
  4.     Dim objMail As Outlook.MailItem
  5.  
  6.     Set appOutlook = CreateObject("Outlook.Application")
  7.     Set objMail = appOutlook.CreateItem(olMailItem)
  8.  
  9.     With objMail
  10.         With .Recipients.Add("qqq")
  11.             .Type = olTo
  12.         End With
  13.         .Subject = "qqq"
  14.         .Body = "qqq"
  15.         .Display
  16.     End With
  17.  
  18.     Set objMail = Nothing
  19.     Set appOutlook = Nothing
  20.  
  21. End Sub
  22.  
  23.  
Sep 18 '07 #8

P: 4
Have a look at this declaration

Dim objOutlookRecip As Outlook.Recipent

Now change it to

Dim objOutlookRecip As Outlook.Recipients

Does that make a difference
Hi M. McCarthy
Thanks for your help.

I changed the line but didn't change anything. It still stopped right at that line for debug. OLE message prompt up I grant access for one minute and nothing happens.
Sep 20 '07 #9

MMcCarthy
Expert Mod 10K+
P: 14,534
Hi M. McCarthy
Thanks for your help.

I changed the line but didn't change anything. It still stopped right at that line for debug. OLE message prompt up I grant access for one minute and nothing happens.
The problem may be that you are adding more than one address in the recipient list. Try changing your code to add one address at a time.
Sep 21 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.