URGENT - Outlook Com-Addin

  • Thread starter Thread starter PJ
  • Start date Start date
P

PJ

Hi

I was hoping someone can help me.
I have setup a trusted outlook Com-Addin and i use the
Addin in a visual basic external executable. The reason
for this is so we can send mail through our visual basic
application as trusted as we just call routines setup in
the trusted DLL in outlook.This all works fine.

My problem is that if outlook is not running and and you
try to send an email from the visual basic application you
get an error message. I need to kick of outlook
automatically in my external executeable so that it is
running so when the email is sent there is no problems.

Does anyone know how to kick of outlook from your vb
application as i have tried -
Set objApp = New Outlook.Application which was suppose to
work and it doesn't.

If you could help i would really appreciate it.

Thanks in advance for your time.

Kind Regards
PJ.
 
Try using a logon if you start Outlook using automation.

Set oOL = CreateObject("Outlook.Application")
Set oNS = oOL.GetNameSpace("MAPI")
oNS.Logon

See if that helps.
 
Hi Ken

I tried that but i get the same message as i am getting.
I get a "Object variable or withblock variable not set"

Please can you help, as this really frustrating, it works
fine with the trusted Com-Addin when outlook is running
but if it's not running and you try to send a mail with
the Com-Addin from your vb application you get this error.
Surely there has to be a way of doing this if your using a
Com-Addin in your vb application ???
I just dont understand why it wont work.

Thanks for your time and help in advance, appreciate it.
 
Does your addin follow best practices and not instantiate unless
there's an Explorer?

If that's the case then you would need to instantiate an Explorer and
then get your COM addin as a member of the COMAddins collection and
toggle its Connect bit after the Explorer was instantiated to
re-initialize the addin.
 
Ken,

I have not done this before and am learning as i am going
along. I'm not sure what you mean exactly ?
I'm not sure what you mean when you say instantiate an
Explorer and then get your COM addin as a member of the
COMAddins collection andtoggle its Connect bit after the
Explorer was instantiated to re-initialize the addin.

In my Addin Onconnection routine i do the following -

Private Sub IDTExtensibility2_OnConnection(ByVal
Application As Object, ByVal ConnectMode As
AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As
Object, custom() As Variant)

Set gobjApp = Application

On Error Resume Next

If gobjApp.Explorers.Count > 0 Then

'AddInInst represents COMAddIn object
AddInInst.object = Me

Set moPublicClass = New ExposedClass

'Create and Initialize a base class
'gBaseClass.InitHandler Application, AddInInst.ProgId

End If

End Sub
 
OK, it looks like you're following the ItemsCB model for a COM addin
(which is excellent). I also see a public class there, which I use all
the time also. You also should be using AddInMon to make sure your
addin initializes if Outlook is started using automation (such as your
program or something like ActiveSynch) so if the user later starts
Outlook with a UI your addin will be available.

When you are starting Outlook using automation from an external
program there are no Explorers. So your On_Connection code doesn't go
to gBaseClass.InitHandler (that shouldn't be commented out BTW).
That's why your call to the addin fails.

Your external code can do something like this:
Dim oOL As Outlook.Application
Dim colExpl As Outlook.Explorers
Dim oExpl As Outlook.Explorer
Dim oFolder As Outlook.MAPIFolder
Dim oAddin As Office.COMAddin

Set oOL = CreateObject("Outlook.Application")
Set oFolder = oOL.Session.GetDefaultFolder(olFolderInbox)
Set colExpl = oOL.Explorers
Set oExpl = colExpl.Add(oFolder) 'this will display the Inbox
Set oAddin = oOL.COMAddins("myAddin.Connect")
oAddin.Connect = False
oAddin.Connect = True 'your addin will now connect
'now you can access your addin and the public class in it
 
OK, you can't just use code fragments without understanding what they
are and what they do.

First thing go to the Resources page at www.microeye.com and download
the sample VB COM addin project ItemsCB. It has complete code for
gBaseClass and is a best practices example of a COM addin. Next on the
Resources pages see the information about AddInMon.

Then look through the posts for this newsgroup and the
microsoft.public.outlook.program_vba group for threads about having an
addin communicate with its property page. I've posted the code to do
that a few times and so have other people. You will need that to
access your COM addin from an external program.

What you are trying to do is a fairly complex thing and an advanced
COM addin technique. Don't expect to master it all at once.
 
Ken,

I will look up this information.
Thanks for all your help.
Appreciate it.

10 out of 10 for your help.

Thanks Again.
 
Back
Top