Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

changing from reference to late binding

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
red6000 - 30 Jun 2007 23:53 GMT
Hi,

I have some code that calls Outlook.  Unfortunatley I have to write the code
on a pc with OL2003, but the PC that it will run on is OL2002 (and so the
reference needs to be Outlook 10.0 not 11.0).  I can't change the reference
on the pc that it will run on, so I think i need to remove the reference and
use late binding, but I'm struggling.  My code is below, what changes do I
need to make?

Public Sub EmailImage(FName As String)

   Dim oOutlookApp As Outlook.Application
   Dim oItem As Outlook.MailItem

   On Error Resume Next
   Set oOutlookApp = GetObject(, "Outlook.Application")
       If Err <> 0 Then
           MsgBox ("There has been a problem connecting to your email
account and the mail will not be sent")
           Exit Sub
       End If

   Set oItem = oOutlookApp.CreateItem(olMailItem)

   With oItem
       .To = "a@b.com"
       .subject = "***FILEONLY***"
       .Attachments.Add Source:=FName
       .body = "Please scan the attached document as FILEONLY"
       .BodyFormat = olFormatPlain
       .Send
   End With

   Set oItem = Nothing
   Set oOutlookApp = Nothing

End Sub
Jonathan West - 01 Jul 2007 01:10 GMT
> Hi,
>
[quoted text clipped - 33 lines]
>
> End Sub

With any luck, you need only change two lines. Change this

   Dim oOutlookApp As Outlook.Application
   Dim oItem As Outlook.MailItem

to this

   Dim oOutlookApp As Object
   Dim oItem As Object

The essence of late binding is that you declare your variables As Object,
and it is only when they are first assigned that the program knows what sort
of object they are. The advantage is being able to deal with multiple
versions, the disadvantage is that you lose type-checking when writing the
code.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.