Hallo,
ich versuche einen Menü aufzubauen (AddIn) für den VBA Editor für Excel und Access mit VB.NET
Der Grund ist es paar spezielle Funktionen für unsere Firma darin zu Integrieren.
Könnte mir jemand ein Buch, Tutorial oä. Dafür vorschlagen,
ich finde nämlich keine Information dafür, außer die von MZ Tools aber, da ich kein Profi bin,
komme ich einfach nicht weiter,
Oder vieleich kann mir jemand bei den Fehler Helfen:
System.ArgumentException: Das System kann den angegebenen Pfad nicht finden.
bei Microsoft.Office.Core._CommandBars.get_Item(Object Index)
bei MenuTest.Connect.InitializeAddIn()in …. MenuTest.vb: Zeile159
Hier der Quellcode:
Dank im Vorauß
Mitrozo
*Topic verschoben*
ich versuche einen Menü aufzubauen (AddIn) für den VBA Editor für Excel und Access mit VB.NET
Der Grund ist es paar spezielle Funktionen für unsere Firma darin zu Integrieren.
Könnte mir jemand ein Buch, Tutorial oä. Dafür vorschlagen,
ich finde nämlich keine Information dafür, außer die von MZ Tools aber, da ich kein Profi bin,
komme ich einfach nicht weiter,
Oder vieleich kann mir jemand bei den Fehler Helfen:
System.ArgumentException: Das System kann den angegebenen Pfad nicht finden.
bei Microsoft.Office.Core._CommandBars.get_Item(Object Index)
bei MenuTest.Connect.InitializeAddIn()in …. MenuTest.vb: Zeile159
Hier der Quellcode:
VB.NET-Quellcode
- Imports Extensibility
- Imports System.Windows.Forms
- Imports System.Runtime.InteropServices
- Imports Microsoft.Vbe.Interop
- Imports Microsoft.Office.Core
- <ComVisible(True), Guid("e5dc17d9-33e7-4253-87a3-20eabdfc56a9"), ProgId("MenuTest.Connect")>
- Public Class Connect
- Implements Extensibility.IDTExtensibility2
- Private _VBE As VBE
- Private _AddIn As AddIn
- 'CommandBar
- Private WithEvents _myStandardCommandBarButton As CommandBarButton
- Private WithEvents _myToolsCommandBarButton As CommandBarButton
- Private WithEvents _myCodeWindowCommandBarButton As CommandBarButton
- Private WithEvents _myToolBarButton As CommandBarButton
- Private WithEvents _myCommandBarPopup1Button As CommandBarButton
- Private WithEvents _myCommandBarPopup2Button As CommandBarButton
- ' CommandBars created by the add-in
- Private _myToolbar As CommandBar
- Private _myCommandBarPopup1 As CommandBarPopup
- Private _myCommandBarPopup2 As CommandBarPopup
- Private Sub OnConnection(Application As Object, ConnectMode As Extensibility.ext_ConnectMode,
- AddInInst As Object, ByRef custom As System.Array) Implements IDTExtensibility2.OnConnection
- Try
- _VBE = DirectCast(Application, VBE)
- _AddIn = DirectCast(AddInInst, AddIn)
- Select Case ConnectMode
- Case Extensibility.ext_ConnectMode.ext_cm_Startup
- ' OnStartupComplete will be called
- Case Extensibility.ext_ConnectMode.ext_cm_AfterStartup
- InitializeAddIn()
- End Select
- Catch ex As Exception
- MessageBox.Show(ex.ToString())
- End Try
- End Sub
- Private Sub OnDisconnection(RemoveMode As Extensibility.ext_DisconnectMode,
- ByRef custom As System.Array) Implements IDTExtensibility2.OnDisconnection
- Try
- Select Case RemoveMode
- Case ext_DisconnectMode.ext_dm_HostShutdown, ext_DisconnectMode.ext_dm_UserClosed
- ' Delete buttons on built-in commandbars
- If Not (_myStandardCommandBarButton Is Nothing) Then
- _myStandardCommandBarButton.Delete()
- End If
- If Not (_myCodeWindowCommandBarButton Is Nothing) Then
- _myCodeWindowCommandBarButton.Delete()
- End If
- If Not (_myToolsCommandBarButton Is Nothing) Then
- _myToolsCommandBarButton.Delete()
- End If
- ' Disconnect event handlers
- _myToolBarButton = Nothing
- _myCommandBarPopup1Button = Nothing
- _myCommandBarPopup2Button = Nothing
- ' Delete commandbars created by the add-in
- If Not (_myToolbar Is Nothing) Then
- _myToolbar.Delete()
- End If
- If Not (_myCommandBarPopup1 Is Nothing) Then
- _myCommandBarPopup1.Delete()
- End If
- If Not (_myCommandBarPopup2 Is Nothing) Then
- _myCommandBarPopup2.Delete()
- End If
- End Select
- Catch e As System.Exception
- System.Windows.Forms.MessageBox.Show(e.ToString)
- End Try
- End Sub
- Private Sub OnStartupComplete(ByRef custom As System.Array) _
- Implements IDTExtensibility2.OnStartupComplete
- InitializeAddIn()
- End Sub
- Private Sub OnAddInsUpdate(ByRef custom As System.Array) Implements IDTExtensibility2.OnAddInsUpdate
- End Sub
- Private Sub OnBeginShutdown(ByRef custom As System.Array) Implements IDTExtensibility2.OnBeginShutdown
- End Sub
- Private Function AddCommandBarButton(ByVal commandBar As CommandBar) As CommandBarButton
- Dim commandBarButton As CommandBarButton
- Dim commandBarControl As CommandBarControl
- commandBarControl = commandBar.Controls.Add(MsoControlType.msoControlButton)
- commandBarButton = DirectCast(commandBarControl, CommandBarButton)
- commandBarButton.Caption = "My button"
- commandBarButton.FaceId = 59
- Return commandBarButton
- End Function
- Private Sub InitializeAddIn()
- ' Constants for names of built-in commandbars of the VBA editor
- Const STANDARD_COMMANDBAR_NAME As String = "Standard"
- Const MENUBAR_COMMANDBAR_NAME As String = "Menu Bar"
- Const TOOLS_COMMANDBAR_NAME As String = "Tools"
- Const CODE_WINDOW_COMMANDBAR_NAME As String = "Code Window"
- ' Constants for names of commandbars created by the add-in
- Const MY_COMMANDBAR_POPUP1_NAME As String = "MyTemporaryCommandBarPopup1"
- Const MY_COMMANDBAR_POPUP2_NAME As String = "MyTemporaryCommandBarPopup2"
- ' Constants for captions of commandbars created by the add-in
- Const MY_COMMANDBAR_POPUP1_CAPTION As String = "My sub menu"
- Const MY_COMMANDBAR_POPUP2_CAPTION As String = "My main menu"
- Const MY_TOOLBAR_CAPTION As String = "My toolbar"
- ' Built-in commandbars of the VBA editor
- Dim standardCommandBar As CommandBar
- Dim menuCommandBar As CommandBar
- Dim toolsCommandBar As CommandBar
- Dim codeCommandBar As CommandBar
- ' Other variables
- Dim toolsCommandBarControl As CommandBarControl
- Dim position As Integer
- Try
- ' Retrieve some built-in commandbars
- standardCommandBar = _VBE.CommandBars.Item(STANDARD_COMMANDBAR_NAME)
- menuCommandBar = _VBE.CommandBars.Item(MENUBAR_COMMANDBAR_NAME)
- toolsCommandBar = _VBE.CommandBars.Item(TOOLS_COMMANDBAR_NAME)
- codeCommandBar = _VBE.CommandBars.Item(CODE_WINDOW_COMMANDBAR_NAME)
- Catch ex As Exception
- System.Windows.Forms.MessageBox.Show(ex.ToString)
- End Try
- MessageBox.Show(_AddIn.ProgId & " loaded in VBA editor version " & _VBE.Version)
- End Sub
- End Class
Dank im Vorauß
Mitrozo
*Topic verschoben*
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Marcus Gräfe“ ()