Outlook COM Addin in Visual Basic

G

Guest

I have developed a Outlook COM Addin in Visual Basic 6. It is working finely on my machine.When I create a package and send it to someone who doesnot have Visual Studio on his system its not working properly. What could be the reason,Plz help.
 
K

Ken Slovak - [MVP - Outlook]

You are probably using some control that was installed by VS and is
not included in your distribution that isn't on the user machine. Or
some library.




Moumita said:
I have developed a Outlook COM Addin in Visual Basic 6. It is
working finely on my machine.When I create a package and send it to
someone who doesnot have Visual Studio on his system its not working
properly. What could be the reason,Plz help.
 
G

Guest

Actually the addin is displaying an error even when we're running on the same machine.
I am attaching the code

purpose of code
===================
when we create a new mail.each of the recepients of that mail get that maIL indivisually,i.e he is not able to see the names of the other recepients

===========================
Option Explicit

Public oApplication As Outlook.Application
Public WithEvents INewInspectors As Outlook.Inspectors
Dim WithEvents bSendMailButton As CommandBarButton
Public MyMail As MailItem

Private Sub AddinInstance_OnBeginShutdown(custom() As Variant)

If Not oApplication Is Nothing Then
Set oApplication = Nothing
End If

Set INewInspectors = Nothing
Set bSendMailButton = Nothing

'MsgBox ("Outlook is shutting down")
'If MyMail Is Not Null Then

'MyMail = Nothing
'End If
'If INewInspectors Is Not Null Then

'INewInspectors = Nothing
'End If
'If oApplication Is Not Null Then

'oApplication = Nothing
'End If
'If bSendMailButton Is Not Null Then

'bSendMailButton = Nothing

'End If

End Sub

'This function gets called when the Addin gets loaded on the Application
Public Sub AddinInstance_OnConnection(ByVal oApp As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)

'Initialize the handler which gets called when a new inspector item
'is created
Set oApplication = oApp

Call Initialize_handler

End Sub

Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)

'If Not oApplication Is Nothing Then
' Set oApplication = Nothing
'End If
On Error Resume Next
MsgBox ("the addin has been disconnected from Outlook")



End Sub

' This function is called when we create a new inspector item,i.e. a new mail

Private Sub INewInspectors_NewInspector(ByVal INewInspectors As Outlook.Inspector)

Dim strButtonTag As String

On Error GoTo ErrorOperation

Set MyMail = INewInspectors.CurrentItem

strButtonTag = "SendToAll"

Set bSendMailButton = INewInspectors.CommandBars("Standard").FindControl(msoControlButton, , strButtonTag, , False)

'Adding a button on the standard command bar of the new mail item if one is not already present

If bSendMailButton Is Nothing Then

Set bSendMailButton = INewInspectors.CommandBars("Standard").Controls.Add(msoControlButton, , , , True)

End If

bSendMailButton.Caption = "SendToAll"
bSendMailButton.Tag = strButtonTag
bSendMailButton.Visible = True
bSendMailButton.Style = msoButtonCaption

GoTo NoError

' if the new inspector item is not a mail then it'll go to the msgbox else continue

ErrorOperation:
'MsgBox "this operation valid only on new mail close this and open a new mail"
NoError:

End Sub
Public Sub Initialize_handler()

Set INewInspectors = oApplication.Inspectors

End Sub

'When the Sendmail button on a new mail is clicked.

Public Sub bSendMailButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)

Dim Item As ContactItem
Dim folderMAPI As NameSpace
Dim fldContact As Outlook.MAPIFolder
Dim colContacts As Outlook.Items
Dim newmail As MailItem
'These are used as counters in for loop
Dim i As Integer
Dim j As Integer
Dim k As Integer

Dim IContFldItem As Object
Dim IDLstItem As DistListItem

Dim mattach As Outlook.Attachment

If (MsgBox("Are you sure, you want to send this mail Individually ? ", vbYesNo) = vbYes) Then


Set folderMAPI = oApplication.GetNamespace("MAPI")
Set fldContact = folderMAPI.GetDefaultFolder(olFolderContacts)
'for each of the recepients of the mail we'll check whether its a
'private distributionlist a public distribution list or a single
'email address
For i = 1 To MyMail.Recipients.Count


If MyMail.Recipients.Item(i).DisplayType = olPrivateDistList Then

'If the recepients of the mail is a private distribution list
'then it'll match the name of the private distribution list
'with each of the items in the contacts folder.
'If a match is found then it accesses each of the members of
'the distribtion list.

For Each IContFldItem In fldContact.Items

If IContFldItem = MyMail.Recipients.Item(i).AddressEntry Then

' we cast the recepients item to a distribution list
'item to access all its properties.

Set IDLstItem = IContFldItem

'For each of the memebers in the distribution list we
'send a mail.

For j = 1 To IDLstItem.MemberCount

Set newmail = Outlook.CreateItem(olMailItem)
newmail.To = IDLstItem.GetMember(j).Address
newmail.Body = MyMail.Body
newmail.Subject = MyMail.Subject

'We attach all the attachments of the dummy mail to
'the mail we're sending to each mamber of the
'distribution list .

For Each mattach In MyMail.Attachments

'we store each attachment item in the user's machine
'temporarily then dicard it later.

mattach.SaveAsFile ("C:\" & mattach.FileName)

newmail.Attachments.Add ("C:\" & mattach.FileName)
Kill ("C:\" & mattach.FileName)

Next mattach

newmail.Send

Set newmail = Nothing

Next j

End If

Next IContFldItem

End If

'If you're sending the mail to a public distribution list

If MyMail.Recipients.Item(i).DisplayType = olDistList Then

For k = 1 To MyMail.Recipients.Item(i).AddressEntry.Members.Count

'Creating a new mail for each of the recepients

Set newmail = Outlook.CreateItem(olMailItem)
newmail.To = MyMail.Recipients.Item(i).AddressEntry.Members.Item(k).Address
newmail.Body = MyMail.Body
newmail.Subject = MyMail.Subject

'Attach all attachments to the mail to be sent

For Each mattach In MyMail.Attachments

'the file to be attached gets stored temporarily and later
'removed after it has been attached to the mail

mattach.SaveAsFile ("C:\" & mattach.FileName)

newmail.Attachments.Add ("C:\" & mattach.FileName)

Kill ("C:\" & mattach.FileName)

Next mattach

newmail.Send

Set newmail = Nothing
Next k

End If

'If the mail recepient is a single user

If MyMail.Recipients.Item(i).DisplayType = olUser Then

'Creating a new mail

Set newmail = Outlook.CreateItem(olMailItem)
newmail.To = MyMail.Recipients.Item(i).AddressEntry
newmail.Body = MyMail.Body
newmail.Subject = MyMail.Subject

For Each mattach In MyMail.Attachments

mattach.SaveAsFile ("C:\" & mattach.FileName)
newmail.Attachments.Add ("C:\" & mattach.FileName)
Kill ("C:\" & mattach.FileName)

Next mattach

newmail.Send
Set newmail = Nothing

End If

Next i

End If
'Destroying the temporary mail
oApplication.ActiveInspector.Close (olDiscard)

Set fldContact = Nothing
Set folderMAPI = Nothing

End Sub


if we start and close outlook without performing any operation,there is no error
when we click on new i.e a new mail is created and sent separately to each of the recepients.then we close outlook there is an error saying
The instruction at "0x3F9994F4" referenced memory at "0x0000001B". The Memory could not be "read". Click OK to terminate the application. Click CANCEL to debug the application.

plz help
 
K

Ken Slovak - [MVP - Outlook]

First, download ItemsCB from the Resources page at www.microeye.com
and follow it's examples on initializing and releasing Outlook objects
and COM addins. Second, make sure you have routines to handle any
errors that might occur in your code, even if only an On Error Resume
Next statement. Next, explicitly release all your objects and don't
rely on them to be released when they go out of scope. Finally, make
sure you resolve all recipients in the message. Oh, and close the mail
item and not the Inspector. See if those things help.




Moumita said:
Actually the addin is displaying an error even when we're running on the same machine.
I am attaching the code
<snip>
 
G

Guest

After freeing all objects i.
Namespace, outlook MAPI folder , outlook items, mailitem, distlistitem, inspectors object, and commandbarbutton
the load behavior of the addin has changed it doesn't load on startup,it loads on demand i.e doesn't load everytime i start outlook.
 
G

Guest

how can I set the load property of the outlook addin? When I go to the connect object i.e right click on the connect.dsr file and set the load property of the addin to Startup and save it .After I start Outlook the load behaviour of the addin changes automatically to load on demand(not currently loaded)
 
K

Ken Slovak - [MVP - Outlook]

Please quote some of the preceding thread when you post, it makes it
very hard to follow a thread otherwise.

Releasing all objects should never change the LoadBehavior of an
addin. Only some other software or an Outlook crash would do that.
What version of Outlook? If 2002 or later see if the addin is listed
in the Disabled Items in the Help, About Microsoft Outlook dialog. If
it is select it and click Enable. Exit and restart Outlook.

You can directly access LoadBehavior from the registry using the Win32
API's and you can access any addin in the COMAddins collection and
toggle the Connection bit to force a load but you shouldn't have to do
that.




Moumita said:
After freeing all objects i.e
Namespace, outlook MAPI folder , outlook items, mailitem,
distlistitem, inspectors object, and commandbarbutton.
the load behavior of the addin has changed it doesn't load on
startup,it loads on demand i.e doesn't load everytime i start outlook.
 
F

Falconetti Daniel

Hello,

Getting in that theard to share my own experience!
I have the same problem :
I developed an add-in with VB6 SP5 that worked well on Office 2K when I
tried it on Office XP the com add in get disabled!
It doesn't crsh on my development machien(even using Office XP)

I had a microsoft incident opened on that and they just noticed that the dll
generated by VB had a problem! not being able to say what happened.
They took my source code and generated the dll on full US installation and
the dll worked fine with no modification!

So could that be the solution, I still need to intall a full US machien to
check that!

wondering as well if using VB.NET would help?

--
Daniel Falconetti
MCSE/MCT
www.falconetti.net

Ken Slovak - said:
Please quote some of the preceding thread when you post, it makes it
very hard to follow a thread otherwise.

Releasing all objects should never change the LoadBehavior of an
addin. Only some other software or an Outlook crash would do that.
What version of Outlook? If 2002 or later see if the addin is listed
in the Disabled Items in the Help, About Microsoft Outlook dialog. If
it is select it and click Enable. Exit and restart Outlook.

You can directly access LoadBehavior from the registry using the Win32
API's and you can access any addin in the COMAddins collection and
toggle the Connection bit to force a load but you shouldn't have to do
that.
.......................;
 
K

Ken Slovak - [MVP - Outlook]

It's a lot harder to set up a VB.Net COM addin that can work across
multiple versions of Outlook than one created using COM. Plus you'd
have to make sure each user has the .NET Framework installed and there
are incompatibilities between different versions of the Framework.

My addins are always created using a development machine that is
running Outlook 2000. That way they are compatible with later versions
of Outlook. I use a US English installation but my code runs on
machines using other language and localization settings. You do have
to be careful about not using localized names for things though.

If your code crashed Outlook and so was disabled on an Outlook 2002
machine I'd also look at other things on that machine. Like was any
application running that might have been involved in the crash. Some
script stoppers and anti-virus email scanning software are known to do
that.

Without knowing what problems PSS found with your code I can't comment
on that, but if you'd like to share what they found it might be
helpful to other people.
 
F

Falconetti Daniel

Well, I checked all other applications running and made tests on a brand new
installation of WinXP SP1 + Office XP SP1 nothing else!

Microsoft hasn't been able yet to say what was wrong with the generated dlls
except to try to install VB6 from an other CD! Which I've done but with same
result!
So I wondered if their wasn't a problem with the localised version of VB
(french) and Win XP/Office XP.

I've installed VB6 on a Win XP machine and when I quit, I've got the an
error asking to send debug info to microsoft.
If I click on debugging button it says that there is an access violation ans
show some machine code!

If I get something new about that, sure I'll share with all of you!

--
Daniel Falconetti
MCSE/MCT
www.falconetti.net
Ken Slovak - said:
It's a lot harder to set up a VB.Net COM addin that can work across
multiple versions of Outlook than one created using COM. Plus you'd
have to make sure each user has the .NET Framework installed and there
are incompatibilities between different versions of the Framework.

My addins are always created using a development machine that is
running Outlook 2000. That way they are compatible with later versions
of Outlook. I use a US English installation but my code runs on
machines using other language and localization settings. You do have
to be careful about not using localized names for things though.

If your code crashed Outlook and so was disabled on an Outlook 2002
machine I'd also look at other things on that machine. Like was any
application running that might have been involved in the crash. Some
script stoppers and anti-virus email scanning software are known to do
that.

Without knowing what problems PSS found with your code I can't comment
on that, but if you'd like to share what they found it might be
helpful to other people.
 
G

Gary Tinker

I too have a similar problem.
Install the addin and it runs OK for some hours but usually after a reboot
it stops working.
I'm not certain yet but it seems to be related to Outlook 2002
It is working without problem on 8 systems running Windows 98/2000/XP and
Outlook 2000

Have you had any further feedback/thoughts on this issue yet?

Gary Tinker





Falconetti Daniel said:
Well, I checked all other applications running and made tests on a brand new
installation of WinXP SP1 + Office XP SP1 nothing else!

Microsoft hasn't been able yet to say what was wrong with the generated dlls
except to try to install VB6 from an other CD! Which I've done but with same
result!
So I wondered if their wasn't a problem with the localised version of VB
(french) and Win XP/Office XP.

I've installed VB6 on a Win XP machine and when I quit, I've got the an
error asking to send debug info to microsoft.
If I click on debugging button it says that there is an access violation ans
show some machine code!

If I get something new about that, sure I'll share with all of you!

--
Daniel Falconetti
MCSE/MCT
www.falconetti.net
"Ken Slovak - [MVP - Outlook]" <[email protected]> a écrit dans le message
de news:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top