0

I want to be able automate certain things in Outlook (ex. compose a new email and populate parts of it). I have much more experience in IT related matters than those that will be using the files.

I had to enabled the Microsoft Outlook 15.0 Library yesterday in order to accomplish what I was doing. Is it possible to not need that enabled on the other computers that are going to use my file? Or enable it within the VBA code? I'm open to other solutions.

I just know that I'm not utilizing a tool (in this case Outlook) that could definitely help me streamline some tasks...

I was reading about early vs late binding yesterday and thought I had changed my code to late binding. But, I am still having issues with it. Here is my code.

Private Sub btnGenerateEmail_Click()
    Dim obApp As Object
    Dim objMsg As MailItem

    Set obApp = Outlook.Application
    Set objMsg = obApp.CreateItem(olMailItem)

    With objMsg
        .To = "test@test.com"
        .cc = "test@test.com"
        .Subject = "Scrap Face Incident Report"
        .Display
    End With
End Sub
BigBen
  • 46,229
  • 7
  • 24
  • 40
mongoose00318
  • 131
  • 2
  • 12
  • Research early versus late binding. Well I'm not sure exactly what your question is. – BigBen Dec 12 '19 at 14:23
  • I was reading about that yesterday actually. I thought I changed my code to work to the late binding technique. Maybe I missed something. Ill edit my post and post my code in it. – mongoose00318 Dec 12 '19 at 14:25
  • You'll know your late binding works if you remove the reference to the Outlook library and the code still succeeds. – BigBen Dec 12 '19 at 14:26
  • `MailItem` and `olMailItem` and `Outlook.Application` are all early binding... see [this question](https://stackoverflow.com/questions/32939197/convert-early-binding-vba-to-late-binding-vba-excel-to-outlook-contacts) for example. – BigBen Dec 12 '19 at 14:27

1 Answers1

1

MailItem and Outlook.Application and olMailItem are all early binding - these belong to the Outlook object model.

Late-binding might look like this:

Private Sub btnGenerateEmail_Click()
    Dim App As Object
    Dim Msg As Object

    Const olMailItem As Long = 0

    Set App = CreateObject("Outlook.Application")
    Set Msg = App.CreateItem(olMailItem)

    With Msg
        .To = "test@test.com"
        .cc = "test@test.com"
        .Subject = "Scrap Face Incident Report"
        .Display
    End With
End Sub
BigBen
  • 46,229
  • 7
  • 24
  • 40