Je dois manipuler l'environnement VBA d'une application à partir d'un additif C# pour pouvoir ajouter des modules, des gestionnaires d'événements, etc. aux documents créés par l'addin.Manipuler l'environnement VBA à partir de C# .Net (VS2008)
Je l'ai déjà fait dans VB.Net mais je ne vois pas comment obtenir l'objet IDE en C#. Suis-je en train de manquer une référence ou une directive Using? Je ne vois rien d'approprié dans les références.
En VB.Net j'ai une référence à Microsoft.VisualBasic et je l'ai fait:
Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Public Module VBA
Private m_VBEnv As 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)
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
J'ai ajouté une référence à Microsoft.VisualBasic à mon C#, mais il ne reconnaît pas VBIDE.VBE.
En outre, comment devrais-je faire le bit DirectCast en C#. Est-ce juste un casting simple?
Des suggestions?