Consulting

Page 1 of 3 1 2 3 LastLast
Results 1 to 20 of 55

Thread: Turn on Resources on Install

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    Turn on Resources on Install

    I use some Outlook code and Word code in my add-in. However sometimes I forget to turn those resources on in the VBA for some of my users. Is there a way to turn them on with code?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Turn on? What do you mean?

  3. #3
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Sorry, I meant the References in VBA under tools on the VBA toolbar

    I have to turn on the Outlook reference library and the Word Reference Library.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Once you have done it in a workbook, it remains. You don't need to do it again.

  5. #5
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    I know that but sometimes when I install it on someone else's machine for the first time I forget to turn it on then when they try to use some of those features they get errors.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    So use late binding, then you can forgte about it.

    So instaed of

    [vba]

    Dim oOutlook As Outlook.Application
    Dim oNameSpace As Outlook.NameSpace
    Dim oMailItem As Outlook.MailItem
    Dim oRecipient As Outlook.Recipient

    Set oOutlook = New Outlook.Application
    Set oNameSpace = oOutlook.GetNamespace("MAPI")
    oNameSpace.Logon , , True

    Set objMailItem = oOutlook.CreateItem(olMailItem)
    [/vba]
    you would use

    [vba]

    Dim oOutlook As Object
    Dim oMailItem As Object
    Dim oRecipient As Object
    Dim oNameSpace As Object


    Set oOutlook = CreateObject("Outlook.Application")
    Set oNameSpace = oOutlook.GetNameSpace("MAPI")
    oNameSpace.Logon , , True


    Set oMailItem = oOutlook.CreateItem(0)
    [/vba]

  7. #7
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    xld,

    what is the difference between early binding and late binding? Here is some code I am using for word:

    [VBA]Documents.Open ("H:\@Business_Reporting_Today\References\Business Reporting Today.doc")[/VBA]

    Here is some code I am using for Outlook:
    [VBA]Sub eMailActiveWorkbook()

    Dim OL As Object
    Dim EmailItem As Object
    Dim WB As Workbook

    TurnOffFeatures
    Set OL = CreateObject("Outlook.Application")
    Set EmailItem = OL.CreateItem(olMailItem)
    Set WB = ActiveWorkbook
    WB.Save
    With EmailItem
    .Attachments.Add WB.FullName
    .Display
    End With

    TurnOnFeatures

    Set WB = Nothing
    Set OL = Nothing
    Set EmailItem = Nothing

    End Sub[/VBA]

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Early binding is just binding to the type library at compile time, late binding is at run time.

    Early binding is more efficient as VBA retrieves information from the library up-front, and uses that throughout, whereas late binding has to go through the registry, find the library, look up the details, every time a reference is made to an object within that library. But early binding ties you to a praticular version, late binding is more flexible.

    With late binding, you cannot use that libraries constants, such as olMailItem, as you will get a compile error if you do. You could declare them as constants in your code, but otherwise you have to use the constant value.
    Last edited by Bob Phillips; 03-13-2007 at 08:28 AM.

  9. #9
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    How do I change this to late binding?

    [VBA]Dim OL As Object
    Dim EmailItem As Object
    Dim WB As Workbook

    TurnOffFeatures
    Set OL = CreateObject("Outlook.Application")
    Set EmailItem = OL.CreateItem(olMailItem)
    Set WB = ActiveWorkbook
    WB.Save
    With EmailItem
    .Attachments.Add WB.FullName
    .Display
    End With

    TurnOnFeatures

    Set WB = Nothing
    Set OL = Nothing
    Set EmailItem = Nothing[/VBA]

  10. #10
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    xld,

    can you fix it so your post is horizontal not vertical?

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It's VBAX, not me, but I will try again
    [vba] Dim OL As Object
    Dim EmailItem As Object
    Dim WB As Workbook
    TurnOffFeatures
    Set OL = CreateObject("Outlook.Application")
    Set EmailItem = OL.CreateItem(0)
    Set WB = ActiveWorkbook
    WB.Save
    With EmailItem
    .Attachments.Add WB.FullName
    .Display
    End With
    TurnOnFeatures
    Set WB = Nothing
    Set OL = Nothing
    Set EmailItem = Nothing
    [/vba]

    Fixed, MD

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It's no good.

  13. #13
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Now it is telling me object variable or with block not set when I try to run the code after I turn off the Outlook references.

  14. #14
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Where?

  15. #15
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    it is weird because it is giving me that error message where I show the form that I created for email options.

    [VBA]emailform.show[/VBA]

  16. #16
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I don't see that line in the code.

  17. #17
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    that is because that code is called from the form

  18. #18
    VBAX Contributor Ivan F Moala's Avatar
    Joined
    May 2004
    Location
    Auckland New Zealand
    Posts
    185
    Location
    Quote Originally Posted by Djblois
    Now it is telling me object variable or with block not set when I try to run the code after I turn off the Outlook references.
    go to your UF code
    Ensure you have Option explicit set.
    Recompile your code.... see where it highlights your error.
    It would appear ypou may still have a early bound reference set.
    Kind Regards,
    Ivan F Moala From the City of Sails

  19. #19
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Thank you all, I got that to work. Now how do I change this to late binding:

    [VBA]Documents.Open ("H:\@Business_Reporting_Today\References\Business Reporting Today.doc")[/VBA]

  20. #20
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That code is neither late nor early.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •