2 Replies Latest reply on Sep 3, 2010 8:18 AM by AlistairFrith

    Manipulate Procbook VBA IDE from C# .Net addin

    AlistairFrith

      I need to manipulate Processbook's VBA environment from a C# addin so I can add modules, event handlers etc to displays that are created by the addin.

       

      I've done it before in VB.Net but can't see how to get at the IDE object in C#. Am I just missing a reference or a Using directive? I can't see anything appropriate in the references.

       

      Since this is generic VBA type stuff, I have posted a question on Stack Overflow but no-one has responded thus far.

       

      In my VB.Net version, I have a reference to Microsoft.VisualBasic and I have done this:

      Imports System
      Imports System.Collections.Generic
      Imports System.Collections.ObjectModel

      Public Module VBA
          Private m_VBEnv As VBIDE.VBE     ' <-- This is the bit I am having trouble doing in C#:
                                           '     It does not know about VBIDE.VBE.
          Private m_dlg As AddInDialog

          Private Structure EventHandler
              Public objectName As String
              Public eventName As String
              Public action As String
          End Structure
          Private m_handlers As New Collection

          Public Function InitVBA(ByVal app As PBObjLib.Application, ByVal dlg As AddInDialog, ByVal scrWidth As Integer, ByVal scrHeight As Integer) As Boolean
              InitVBA = False
              Try
                  m_dlg = dlg
                  m_VBEnv = DirectCast(app.VBE, VBIDE.VBE)      ' <-- Also this bit, again because of VBIDE.VBE
                  m_VBEnv.MainWindow.Height = 480
                  m_VBEnv.MainWindow.Width = 640
                  m_VBEnv.MainWindow.Left = (scrWidth - m_VBEnv.MainWindow.Width)
                  m_VBEnv.MainWindow.Top = ((scrHeight - m_VBEnv.MainWindow.Height) - 50)
                  m_VBEnv.MainWindow.WindowState = VBIDE.vbext_WindowState.vbext_ws_Minimize ' .vbext_ws_Normal
                  HideVBWindow()
                  InitVBA = True
              Catch e As Exception
                  dlg.LogMessage(AddInDialog.LogLevel.Err, "Failed to initialise VBA: " & e.Message)
              End Try

          End Function

          ...

      End Module

      I have added a reference to Microsoft.VisualBasic to my C# but it does not recognise VBIDE.VBE.

       

      Also, how would I do the DirectCast bit in C#. Is it just a simple cast?

       

      Any suggestions?

       

      --- Alistair.