Group:  Microsoft Outlook ยป microsoft.public.outlook.interop
Thread: Late binding sample

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Late binding sample
"John" <John[ at ]nospam.infovis.co.uk> 23.02.2006 23:34:47
Hi

I have the below code for communicating with outlook. What changes do I need
to do to late bind this code so it does not need references to any
particular version of outlook.

Many Thanks

Regards


Imports System.Reflection
Imports Outlook

Module modContacts
Dim O As Outlook.Application
Dim F As Outlook.MAPIFolder
Dim iCon As Outlook.ContactItem

Sub Contacs2Outlook()

O = New Outlook.Application
F =
O.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
oContact = DirectCast(F.Items.Item(1), Outlook.ContactItem)
oContact.Delete()

iCon = CType(F.Items().Add(Outlook.OlItemType.olContactItem),
Outlook.ContactItem)
F.Items().Add(Outlook.OlItemType.olContactItem)
With iCon
.CompanyName = "My Computer"
.Categories = "Clients"
.Save()
End With
End Sub
End Module


RE: Late binding sample
Eric Legault [MVP - Outlook] 24.02.2006 20:47:30
It would be something like this I believe:

Dim O As Object
Dim F As Object
Dim iCon As Object

Sub Contacs2Outlook()

Dim oContact As Object
O = CreateObject("Outlook.Application")
F = O.Session.GetDefaultFolder(10)
oContact = DirectCast(F.Items.Item(1), Outlook.ContactItem)
oContact.Delete()

iCon = CType(F.Items().Add(2), Outlook.ContactItem)
F.Items().Add(2)
With iCon
.CompanyName = "My Computer"
.Categories = "Clients"
.Save()
End With
End Sub

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"John" wrote:

[Quoted Text]
> Hi
>
> I have the below code for communicating with outlook. What changes do I need
> to do to late bind this code so it does not need references to any
> particular version of outlook.
>
> Many Thanks
>
> Regards
>
>
> Imports System.Reflection
> Imports Outlook
>
> Module modContacts
> Dim O As Outlook.Application
> Dim F As Outlook.MAPIFolder
> Dim iCon As Outlook.ContactItem
>
> Sub Contacs2Outlook()
>
> O = New Outlook.Application
> F =
> O.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
> oContact = DirectCast(F.Items.Item(1), Outlook.ContactItem)
> oContact.Delete()
>
> iCon = CType(F.Items().Add(Outlook.OlItemType.olContactItem),
> Outlook.ContactItem)
> F.Items().Add(Outlook.OlItemType.olContactItem)
> With iCon
> .CompanyName = "My Computer"
> .Categories = "Clients"
> .Save()
> End With
> End Sub
> End Module
>
>
>
Re: Late binding sample
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 24.02.2006 21:09:18
Although if not logged in already in that context I'd probably want to use
GetNameSpace("MAPI") rather than Session. Some things aren't right if you
use Session that way, it doesn't touch the store.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Eric Legault [MVP - Outlook]" <elegaultZZZ[ at ]REMOVEZZZmvps.org> wrote in
message news:DDBB36D6-4F2C-4673-8185-96388FEAAEA5[ at ]microsoft.com...
[Quoted Text]
> It would be something like this I believe:
>
> Dim O As Object
> Dim F As Object
> Dim iCon As Object
>
> Sub Contacs2Outlook()
>
> Dim oContact As Object
> O = CreateObject("Outlook.Application")
> F = O.Session.GetDefaultFolder(10)
> oContact = DirectCast(F.Items.Item(1), Outlook.ContactItem)
> oContact.Delete()
>
> iCon = CType(F.Items().Add(2), Outlook.ContactItem)
> F.Items().Add(2)
> With iCon
> .CompanyName = "My Computer"
> .Categories = "Clients"
> .Save()
> End With
> End Sub
>
> --
> Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
> Try Picture Attachments Wizard for Outlook:
> http://www.collaborativeinnovations.ca
> Blog: http://blogs.officezealot.com/legault/
>
>
> "John" wrote:
>
>> Hi
>>
>> I have the below code for communicating with outlook. What changes do I
>> need
>> to do to late bind this code so it does not need references to any
>> particular version of outlook.
>>
>> Many Thanks
>>
>> Regards
>>
>>
>> Imports System.Reflection
>> Imports Outlook
>>
>> Module modContacts
>> Dim O As Outlook.Application
>> Dim F As Outlook.MAPIFolder
>> Dim iCon As Outlook.ContactItem
>>
>> Sub Contacs2Outlook()
>>
>> O = New Outlook.Application
>> F =
>> O.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
>> oContact = DirectCast(F.Items.Item(1), Outlook.ContactItem)
>> oContact.Delete()
>>
>> iCon = CType(F.Items().Add(Outlook.OlItemType.olContactItem),
>> Outlook.ContactItem)
>> F.Items().Add(Outlook.OlItemType.olContactItem)
>> With iCon
>> .CompanyName = "My Computer"
>> .Categories = "Clients"
>> .Save()
>> End With
>> End Sub
>> End Module
>>
>>
>>

Re: Late binding sample
"Sue Mosher [MVP-Outlook]" <suemvp[ at ]outlookcode.com> 24.02.2006 21:32:29
Another potential issue is those pesky anti-virus programs that block calls to CreateObject("Outlook.Application.")

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> wrote in message news:ujSGXaYOGHA.1832[ at ]TK2MSFTNGP11.phx.gbl...
[Quoted Text]
> Although if not logged in already in that context I'd probably want to use
> GetNameSpace("MAPI") rather than Session. Some things aren't right if you
> use Session that way, it doesn't touch the store.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Options
> http://www.slovaktech.com/products.htm
>
>
> "Eric Legault [MVP - Outlook]" <elegaultZZZ[ at ]REMOVEZZZmvps.org> wrote in
> message news:DDBB36D6-4F2C-4673-8185-96388FEAAEA5[ at ]microsoft.com...
>> It would be something like this I believe:
>>
>> Dim O As Object
>> Dim F As Object
>> Dim iCon As Object
>>
>> Sub Contacs2Outlook()
>>
>> Dim oContact As Object
>> O = CreateObject("Outlook.Application")
>> F = O.Session.GetDefaultFolder(10)
>> oContact = DirectCast(F.Items.Item(1), Outlook.ContactItem)
>> oContact.Delete()
>>
>> iCon = CType(F.Items().Add(2), Outlook.ContactItem)
>> F.Items().Add(2)
>> With iCon
>> .CompanyName = "My Computer"
>> .Categories = "Clients"
>> .Save()
>> End With
>> End Sub
>>
>> --
>> Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
>> Try Picture Attachments Wizard for Outlook:
>> http://www.collaborativeinnovations.ca
>> Blog: http://blogs.officezealot.com/legault/
>>
>>
>> "John" wrote:
>>
>>> Hi
>>>
>>> I have the below code for communicating with outlook. What changes do I
>>> need
>>> to do to late bind this code so it does not need references to any
>>> particular version of outlook.
>>>
>>> Many Thanks
>>>
>>> Regards
>>>
>>>
>>> Imports System.Reflection
>>> Imports Outlook
>>>
>>> Module modContacts
>>> Dim O As Outlook.Application
>>> Dim F As Outlook.MAPIFolder
>>> Dim iCon As Outlook.ContactItem
>>>
>>> Sub Contacs2Outlook()
>>>
>>> O = New Outlook.Application
>>> F =
>>> O.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
>>> oContact = DirectCast(F.Items.Item(1), Outlook.ContactItem)
>>> oContact.Delete()
>>>
>>> iCon = CType(F.Items().Add(Outlook.OlItemType.olContactItem),
>>> Outlook.ContactItem)
>>> F.Items().Add(Outlook.OlItemType.olContactItem)
>>> With iCon
>>> .CompanyName = "My Computer"
>>> .Categories = "Clients"
>>> .Save()
>>> End With
>>> End Sub
>>> End Module
>>>
>>>
>>>
>

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net