Results 1 to 16 of 16

Thread: Outlook 2003: How to programmitically add code to ThisOutlookSession

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Posts
    131

    Outlook 2003: How to programmitically add code to ThisOutlookSession

    Hi,
    I know it is possible to add procedures and lines to a module through VBA, however is it possible to add procedures and lines to ThisOutlookSession?

    Here is my code:

    VB Code:
    1. Public Sub cmdOK_click()
    2. Dim i As Integer
    3. Dim VBCodeMod As CodeModule
    4. Dim LineNum As Long
    5. Dim button_num As String
    6. Dim button_num_int As Integer
    7.  
    8. [COLOR=Red][B]Set VBCodeMod = VBE.ActiveVBProject.VBComponents("ThisOutlookSession").CodeModule[/B][/COLOR]
    9.    
    10.     For i = old_num_DBs To new_num_DBs
    11.         With VBCodeMod
    12.             LineNum = .ProcCountLines("Application_MAPILogonComplete", vbext_pk_Proc)
    13.             button_num = Right$(Left$(.Lines(.ProcBodyLine("Application_MAPILogonComplete", vbext_pk_Proc), 1), 18), 1)
    14.             button_num_int = CInt(button_num)
    15.             .InsertLines 1, "Public WithEvents oMnuTrackerSub" & button_num_int & " As Office.CommandBarButton"
    16.             .InsertLines .ProcBodyLine("Application_MAPILogonComplete", vbext_pk_Proc), "Dim oCBmnuTracker" & button_num_int + 1 & " As Office.CommandBarButton"
    17.             .InsertLines button_num_int + 10, "Set oCBmnuTracker" & button_num_int & " = oCBmnuAddToTrackerMain.Controls.Add(msoControlButton, 1, , , False)"
    18.             .InsertLines LineNumb, "With oCBmnuTracker" & button_num_int _
    19.                 & vbCr & "   .BeginGroup = False" _
    20.                 & vbCr & "   .Caption = " & lstDBadd.ListItems(i) _
    21.                 & vbCr & "   .Enabled = True" _
    22.                 & vbCr & "   .Style = msoControlCustom" _
    23.                 & vbCr & "   .Visible = True" _
    24.                 & vbCr & "End With" _
    25.                 & vbCr & "Set oMnuTrackerSub" & button_num_int & " = oCBmnuTracker" & button_num_int
    26.             button_added = True
    27.             'name_button_added = lstDBadd.ListItems(i)
    28.         End With
    29.     Next i
    30.  
    31. Set VBCodeMod = Nothing
    32. End Sub




    The red line is where my error occurs. Does anyone know how to reference ThisOutlookSession properly?
    Last edited by RiceRocket; Apr 25th, 2006 at 02:51 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width