vbaproject.otm issues - help required please

New2VB

Registered User.
Local time
Today, 22:20
Joined
Jun 9, 2010
Messages
131
Thanks to the great and wonderful darbid I have a listener in my Access database listening for any incoming Outlook emails.

What I had not discovered is that the Outlook code is not very portable though so having unsuccessfully tried several methods of getting the code to run on two other machines I am appealing once again to the gurus.

Has anybody been able to deploy their vbaproject.otm files to other machines?

Thanks once again for your advice.
 
Hi Darbid, nice to "see" you again....

Yes, I've seen those. As well as:-
http://www.outlookbanter.com/outlook-vba/7477-vbaproject-otm-not-read-anymore.html
http://www.outlookcode.com/article.aspx?ID=36
http://support.microsoft.com/Default.aspx?kbid=290780
http://support.microsoft.com/kb/291163/EN-US/
http://support.microsoft.com/kb/290779/EN-US/
http://support.microsoft.com/kb/290780/EN-US/
http://msdn.microsoft.com/en-us/library/Aa140126
and a few others

Basically, according to outlookcode.com you can try the renaming method, the cut-&-paste method, the import-export method or the office profile wizard (2 methods). I have tried all of them without success and was querying the forum if anyone had found another (unsupported) way. I would hate for all the hard work that you and I put in getting the module to work in the first place.

I would like to have a COM add-in but while researching the methodology I realised this was way over my head (although I did get as far as installing Visual Studio Express).

I was thinking that maybe another way of doing it, considering that all users use the same front-end, is to link Access to an exchange public folder, which I have done for testing. I am not sure whether new mail will automatically be added to the table that incoming mail needs to go to or whether Access will need to poll the public folder every few seconds looking for mail.

If I can use the linking method I found quite a good code-sample here http://www.outlookexchange.com/articles/ricardosilva/out2acc.asp which I would try to combine with this method of opening Access if it is not already open http://www.codeforexcelandoutlook.com/excel-vba/check-if-office-app-is-running/

Your thoughts?... and thanks for replying to my query
 
I would like to have a COM add-in but while researching the methodology I realised this was way over my head (although I did get as far as installing Visual Studio Express).
I have no experience with any of the other methods you talk about. And thus really do not want to answer them.

I have only made COM addins. I have also only used VB6 to make them as the COM addin works without the need for other interopability files to be downloaded which the users did not have.

The VB6 editor is still around and you might find a download somewhere. If you do I am pretty sure we would get the add in done.

Using Visual Studio; Well I have not used it yet - i would like to though. But I think the Express version does not make the templates for you and VS2010 has dropped native support for Office 2003 (although there are workarounds)

There are lots of tutorials on making addins. The one that is the best and where I learnt it is here. http://www.vbforums.com/showthread.php?t=406636 Now Outlook behaves a little strangely in addins so I am sure you willl have questions there. But trust me after you spend the time learning this for one Office Program you can do it for them all. I am onto my 4th addin - I have made 2 for outlook and 1 for Word/Excel each (but I am still in vb6).

I am pretty sure if you follow the tutorial above you will get a basic addin.dll.
 
Hi Darbid,

Now that I have the month-end out of the way I can get back to you. I haven't found a VB6 editor or VS .net2003 and I have tried all the Express editions (2K5, 2K8, 2K10) none of which are any good.

I have managed to find Visual Studio 2005 but I will probably only get to playing with it tomorrow.
 
The point with the versions is this.

Visual Studio 6 is old and COM based thus a lot easier for a VBAer to understand in my opinion.

Visual Studio 2003 onwards is .Net based which adds all the interop stuff to the task - this is where I have problems.

However up until Visual Studio 2010 they all gave you nice templates for making addins for Office 2003. Now in 2010 the 2003 templates are gone. I fear that the express version never had them anyway.
 
Hi Darbid,

Ok, the story so far...

I have found and installed VB6 on one machine and installed Visual Studio on a second machine.

Trying to work out what is going on I have attempted to merge the code and/or concepts of your code, this (http://msdn.microsoft.com/en-us/library/Aa140126) and this (http://www.vbforums.com/showthread.php?t=406636)

I have then ended up with
Code:
Implements IDTExtensibility2

Public WithEvents olInbox As Outlook.Items

Dim WithEvents oApp As Outlook.Application
Dim WithEvents oNS As Outlook.NameSpace
Dim oFolder As Outlook.MAPIFolder
'Dim oCB As Office.CommandBarButton
'Dim oCBs As Office.CommandBars
'Dim oMenuBar As Office.CommandBar

'Dim WithEvents oMyCB As Office.CommandBarButton
'Dim WithEvents oResetCB As Office.CommandBarButton

Public Sub IDTExtensibility2_OnAddInsUpdate( _
        custom() As Variant)

    ' Use this subroutine when Add-ins are updated.
    MsgBox "OnAddInsUpdate called"

End Sub

' Use this subroutine when the host app is shutting down.
' You should persist or destroy your objects in this
' subroutine.
Public Sub IDTExtensibility2_OnBeginShutdown( _
    custom() As Variant)

    MsgBox "OnBeginShutdown called"
    On Error Resume Next

    Set oApp = Nothing
    'Set oCBs = Nothing
    'Set oMenuBar = Nothing
    'Set oMyCB = Nothing
    Set oNS = Nothing
    'Set oCB = Nothing
    'Set oResetCB = Nothing
    Set oFolder = Nothing
End Sub

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

    ' This subroutine is called when your Add-in is connected
    ' to by the host application.
    MsgBox "OnConnection called"
    ' Get the Application object for Outlook.
    Set oApp = Application
    ' Get the Namespace.
    Set oNS = oApp.GetNamespace("MAPI")
    
    If (ConnectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup) Then Call olInbox_ItemAdd(custom)
    ' Get a Folder to extend with the PropPage extension.
    ' Let the user pick the folder.
    ' Set oFolder = oNS.PickFolder()
    ' Customize the Outlook Menu structure and toolbar.
    ' Set oCBs = oApp.ActiveExplorer.CommandBars
    ' Set oMenuBar = oCBs.Add("CustomMenu", , True, True)
    ' oMenuBar.Visible = True
    ' Set oMyControl = _
    '    oMenuBar.Controls.Add(msoControlPopup, , , , True)
    ' oMyControl.Caption = "&Menu Item"
    ' Set oResetCB = oMyControl.Controls.Add( _
    '    Type:=msoControlButton, Temporary:=True, Before:=1)
    ' oResetCB.Caption = "&Reset Menu"
    ' oResetCB.Enabled = True
    ' Set oMyCB = oMyControl.Controls.Add( _
    '    Type:=msoControlButton, Temporary:=True, Before:=1)
    ' oMyCB.Caption = "&Test Menu Item"
    ' oMyCB.Enabled = True
          
End Sub

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

    ' This Sub is called when your add-in is
    ' disconnected from the host.
    MsgBox "OnDisconnection called"
End Sub

Private Sub olInbox_ItemAdd(ByVal Item As Object)
    On Error GoTo Err_olInbox_ItemAdd

        Dim appAccess As Object 'late binding of the MSAccess object
        Dim objDBase As Object 'late binding

        MsgBox ("My Item Class is " & Item.Class)

        If Item.Class = 43 Then
            appAccess = GetObject(, "Access.Application") 'get a database

        If TypeName(appAccess) = "Nothing" Then MsgBox ("Failed to get Access")

            objDBase = appAccess.CurrentDb

        If TypeName(objDBase) = "Nothing" Then MsgBox ("Failed to get current DB")

            MsgBox ("objDBase.Name is " & objDBase.Name)

        If objDBase.Name = "C:\Console\ConsoleIIIv2.7.7.mdb" Then 'here I check the name of the current database - incase there is more than one open
            appAccess.Run ("fromOutlook")
            End If

            appAccess = Nothing
            objDBase = Nothing

        End If
Exit_olInbox_ItemAdd:

        Exit Sub

Err_olInbox_ItemAdd:
        MsgBox(Err.Description & " olInbox_ItemAdd", vbCritical, "Error")
        Resume Exit_olInbox_ItemAdd

    End Sub
       
Private Sub Application_Startup()
        MsgBox ("Outlook Opening")
        olInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
    End Sub
    
    Private Sub Application_Quit()
        MsgBox ("Outlook Closing")
        olInbox = Nothing
    End Sub

This is way over my head so once you have stopped laughing could you let me know your opinion please?
 
and here is the VS2005 version pretty much copied and pasted from http://www.vbforums.com/showthread.php?t=406636
Code:
Option Explicit On
Option Strict Off

Imports Extensibility
Imports System.Runtime.InteropServices

#Region " Read me for Add-in installation and setup information. "
' When run, the Add-in wizard prepared the registry for the Add-in.
' At a later time, if the Add-in becomes unavailable for reasons such as:
'   1) You moved this project to a computer other than which is was originally created on.
'   2) You chose 'Yes' when presented with a message asking if you wish to remove the Add-in.
'   3) Registry corruption.
' you will need to re-register the Add-in by building the $SAFEOBJNAME$Setup project, 
' right click the project in the Solution Explorer, then choose install.
#End Region

<GuidAttribute("1A12FCC8-8529-4979-B053-3684EFBE2B72"), ProgIdAttribute("MyAddin1.Connect")> _
Public Class Connect

    Implements Extensibility.IDTExtensibility2

    Public applicationObject As Object
    Public addInInstance As Object
    Public WithEvents olInbox As Outlook.Items

    Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
        MsgBox("Shutting Down")
    End Sub

    Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate
    End Sub

    Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
        MsgBox("Startup Complete")
    End Sub

    Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection
        MsgBox("Unloading")
    End Sub

    Public Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
        MsgBox("Connecting...")
        applicationObject = application
        addInInstance = addInInst
        If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup) Then Call olInbox_ItemAdd(custom)
    End Sub
    Private Sub olInbox_ItemAdd(ByVal Item As Object) Implements Extensibility.IDTExtensibility2.olInbox_ItemAdd
        On Error GoTo Err_olInbox_ItemAdd

        Dim appAccess As Object 'late binding of the MSAccess object
        Dim objDBase As Object 'late binding

        MsgBox("My Item Class is " & Item.Class)


        If Item.Class = 43 Then
            appAccess = GetObject(, "Access.Application") 'get a database

            If TypeName(appAccess) = "Nothing" Then MsgBox("Failed to get Access")

            objDBase = appAccess.CurrentDb

            If TypeName(objDBase) = "Nothing" Then MsgBox("Failed to get current DB")

            MsgBox("objDBase.Name is " & objDBase.Name)

            If objDBase.Name = "C:\Console\ConsoleIIIv2.7.7.mdb" Then 'here I check the name of the current database - incase there is more than one open
                appAccess.Run("fromOutlook", Item)
            End If

            appAccess = Nothing
            objDBase = Nothing

        End If


Exit_olInbox_ItemAdd:

        Exit Sub

Err_olInbox_ItemAdd:
        MsgBox(Err.Description & " olInbox_ItemAdd", vbCritical, "Error")
        Resume Exit_olInbox_ItemAdd

    End Sub
    Private Sub Application_Quit()
        MsgBox("Outlook Closing")
        olInbox = Nothing
    End Sub

    Private Sub Application_Startup()
        MsgBox("Outlook Opening")
        olInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
    End Sub
End Class
 
Does outlook with the addin shut down properly or does it stay in the task manager?

IF it is not closing down here are some comments.

Now that you are using an Addin you do not need the Application start up or shut down events. They fire too late in the scheme of events.

On connection and On Disconnection are fired when Outlook starts and loads your addin.

The rule is everything you SET you must release. And you must release the main Outlook Object last.

But if it is working like it is then dont change it.

You might also add some error message if the user does not have MSAccess and your MDb turned on.

For me also this kind of addin is pretty annoying I have to have my MDB on all the time I have Outlook on. Also I have to turn My MDB on before I open outlook as outlook will receive lots of email on start up.
 
Let the games begin...

Using the VB6 code I get no errors when I build the dll, then follow these instructions http://www.ehow.com/how_6250242_create-installer-vb6-program.html, and run the installer. Having tested it now it doesn't work when Outlook receives new mail nor does it launch any msgboxes. How can I tell if Outlook is acknowledging or using the add-in.

Using the VS code I get 4 errors when running through the code
1. Type 'Outlook.Items' is not defined
2.'olInbox_ItemAdd' cannot implement 'ilInbox_ItemAdd' because there is no matching sub on inteface 'Extensibility.IDTExtensibility2'
3.Name 'Application' is not declared
4.Name 'olFolderInbox' is not declared
 
Using the VB6 code I get no errors when I build the dll, then follow these instructions

What? Are you using a Microsoft Visual Studio 6.0 for this VB6? If yes then make your .dll and then just Register it with windows yourself. In fact when you make the dll it is automatically registered in that computer.

Register yourself means to open CMD and enter

Code:
regsvr32 "fullpath\FileName.dll"

Using the VS code I get 4 errors when running through the code
1. Type 'Outlook.Items' is not defined
2.'olInbox_ItemAdd' cannot implement 'ilInbox_ItemAdd' because there is no matching sub on inteface 'Extensibility.IDTExtensibility2'
3.Name 'Application' is not declared
4.Name 'olFolderInbox' is not declared

One word for you "Debug". Learn how to do it with VS and addins.

I have to say again I have no experience with making these other than with Visual Studio 6.0 which is really old. But I am pretty sure you do not need to make an install thing, you can get the .dll and just register it. The method of registration will depend on your Operating System. I am also still using XP so it is easier. But they should also register under Vista and 7.
 

Users who are viewing this thread

Back
Top Bottom