Mark Schneider
2007-10-11 10:23:34 UTC
Hallo,
wir haben leider "nur" Office 2003 Professional (kein Developer) und weder
VSTO
noch Visual Studio auf den Entwicklerworkstations. Daher versuchen wir, ein
kleines
Menü-Addin für den VBE in Access 2003 in reinem VBA zu erstellen.
Das funktioniert auch ganz gut und tut so wie wir wollen (usysreginfo wurde
aufgebaut,
mdb als mda umbenannt und wird vom Add-In-Manager erkannt), aber man muss
das Add-In
jedesmal einmal aufrufen, um die Symbolleiste aufzubauen, was auf Dauer
etwas lästig wäre.
Weder mit AddinInstance_OnConnection noch mit IDTExtensibility2_OnConnection
komme ich zu Potte, weil ich einfach nicht weiß, wie ich die ansprechen soll
bzw.
als Events für das Add-In nutzbar mache.
Gibt es da eine Möglichkeit oder weiß jemand, der mit einer Office Developer
gesegnet ist,
was Access da noch anlegt?
Natürlich kann man auf Visual Studio oder Visual Basic zurückgreifen, aber
vielleicht braucht
es die Kanone für unseren Spatzen gar nicht. Wäre klasse, wenn jemand eine
Idee oder
die richtige Erfahrung beisteuern kann...
Vielen Dank im voraus
Mark
Darf nicht alles posten, aber damit Ihr sehen könnt, was ich gerade verzapfe
---------------------------
Modul "myAddin":
Option Compare Database
Option Explicit
Dim oBtns As New Collection
Public Function myAddIn_start()
Set oBtns = Nothing
myAddIn_AddCommandBar ("myAddIn")
myAddIn_AddCommandBarButton "myAddIn", "Nummerieren", "numbering", 1553
myAddIn_AddCommandBarButton "myAddIn", "Einrücken", "indent", 2138
End Function
Function myAddIn_AddCommandBar(ByVal cCBname As String)
Dim cb As CommandBar
For Each cb In Application.VBE.CommandBars
If cb.Name = cCBname Then
myAddIn_removeCommandBar cCBname
End If
Next
Set cb = Application.VBE.CommandBars.Add(Name:=cCBname,
Position:=msoBarTop, temporary:=False)
cb.Visible = True
End Function
Function myAddIn_AddCommandBarButton(ByVal cCBname As String, _
ByVal cBtnCaption As String, _
ByVal cBtnTag As String, _
ByVal cBtnFaceID As Integer)
Dim cb As CommandBar
Dim oEvt As cls_myAddIn_ButtonEvents
Set cb = Application.VBE.CommandBars.Item(cCBname)
'Umweg über Klassenevents ist nötig, da in der VBE die Command
'Buttons nicht wirklich onaction unterstützen :(
'siehe:http://support.microsoft.com/default.aspx?scid=kb;en-us;Q280607
Set oEvt = New cls_myAddIn_ButtonEvents
Set oEvt.oBtn = cb.Controls.Add(msoControlButton)
With oEvt.oBtn
'.Style = msoButtonIconAndWrapCaption
.Style = msoButtonIconAndCaption
.Caption = cBtnCaption
.Tag = cBtnTag
.FaceId = cBtnFaceID
End With
oBtns.Add oEvt
End Function
Function myAddIn_removeCommandBar(ByVal cCBname As String)
Dim cb As CommandBar
For Each cb In Application.VBE.CommandBars
If cb.Name = cCBname Then
Application.VBE.CommandBars.Item(cCBname).Delete
Exit Function
End If
Next
End Function
Function myAddIn_buttonClick(ByVal cBtnTag As String)
MsgBox ("You clicked: " & cBtnTag)
End Function
' die wird nie aufgerufen
Public Sub AddinInstance_OnConnection(ByVal _
Application As Object, ByVal ConnectMode As _
AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst _
As Object, custom() As Variant)
MsgBox ("TEST!")
End Sub
--------------------------------------
Klassenmodul 'cls_myAddIn_ButtonEvents':
--------------------------------------
Public WithEvents oBtn As CommandBarButton
Private Sub oBtn_click(ByVal ctrl As Office.CommandBarButton, CancelDefault
As Boolean)
DCode_buttonClick ctrl.Tag
End Sub
---------------------------
Tabelle uSysRegInfo:
---------------------------
Subkey;Type;ValName;Value
HKEY_CURRENT_ACCESS_PROFILE\Menu Add-ins\&myAddin;0;;
HKEY_CURRENT_ACCESS_PROFILE\Menu
Add-ins\&myAddin;1;Library;|ACCDIR\myAddin.mda
HKEY_CURRENT_ACCESS_PROFILE\Menu
Add-ins\&myAddin;1;Expression;=myAddin_start()
HKEY_CURRENT_ACCESS_PROFILE\Menu Add-ins\&myAddin;1;Version;3
---------------------------
kläglicher Versuch eines zusätzlichen Klassenmoduls, wie wird das dann
angesprochen?
---------------------------
Option Compare Database
Option Explicit
Implements AddInDesignerObjects.IDTExtensibility2
Public appHostApp As Application
Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
' not used but required by Implements.
MsgBox ("Hallohallo1")
End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
' keep this
End Sub
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)
Set appHostApp = Application
'Set ThisCAI = AddInInst
'Set ExcelEvents = New CExcelEvents
MsgBox ("Hallohallo2")
End Sub
Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As
AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
Set appHostApp = Nothing
'Set ThisCAI = Nothing
'Set ExcelEvents = Nothing
MsgBox ("Hallohallo3")
End Sub
Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
'keep this
End Sub
wir haben leider "nur" Office 2003 Professional (kein Developer) und weder
VSTO
noch Visual Studio auf den Entwicklerworkstations. Daher versuchen wir, ein
kleines
Menü-Addin für den VBE in Access 2003 in reinem VBA zu erstellen.
Das funktioniert auch ganz gut und tut so wie wir wollen (usysreginfo wurde
aufgebaut,
mdb als mda umbenannt und wird vom Add-In-Manager erkannt), aber man muss
das Add-In
jedesmal einmal aufrufen, um die Symbolleiste aufzubauen, was auf Dauer
etwas lästig wäre.
Weder mit AddinInstance_OnConnection noch mit IDTExtensibility2_OnConnection
komme ich zu Potte, weil ich einfach nicht weiß, wie ich die ansprechen soll
bzw.
als Events für das Add-In nutzbar mache.
Gibt es da eine Möglichkeit oder weiß jemand, der mit einer Office Developer
gesegnet ist,
was Access da noch anlegt?
Natürlich kann man auf Visual Studio oder Visual Basic zurückgreifen, aber
vielleicht braucht
es die Kanone für unseren Spatzen gar nicht. Wäre klasse, wenn jemand eine
Idee oder
die richtige Erfahrung beisteuern kann...
Vielen Dank im voraus
Mark
Darf nicht alles posten, aber damit Ihr sehen könnt, was ich gerade verzapfe
---------------------------
Modul "myAddin":
Option Compare Database
Option Explicit
Dim oBtns As New Collection
Public Function myAddIn_start()
Set oBtns = Nothing
myAddIn_AddCommandBar ("myAddIn")
myAddIn_AddCommandBarButton "myAddIn", "Nummerieren", "numbering", 1553
myAddIn_AddCommandBarButton "myAddIn", "Einrücken", "indent", 2138
End Function
Function myAddIn_AddCommandBar(ByVal cCBname As String)
Dim cb As CommandBar
For Each cb In Application.VBE.CommandBars
If cb.Name = cCBname Then
myAddIn_removeCommandBar cCBname
End If
Next
Set cb = Application.VBE.CommandBars.Add(Name:=cCBname,
Position:=msoBarTop, temporary:=False)
cb.Visible = True
End Function
Function myAddIn_AddCommandBarButton(ByVal cCBname As String, _
ByVal cBtnCaption As String, _
ByVal cBtnTag As String, _
ByVal cBtnFaceID As Integer)
Dim cb As CommandBar
Dim oEvt As cls_myAddIn_ButtonEvents
Set cb = Application.VBE.CommandBars.Item(cCBname)
'Umweg über Klassenevents ist nötig, da in der VBE die Command
'Buttons nicht wirklich onaction unterstützen :(
'siehe:http://support.microsoft.com/default.aspx?scid=kb;en-us;Q280607
Set oEvt = New cls_myAddIn_ButtonEvents
Set oEvt.oBtn = cb.Controls.Add(msoControlButton)
With oEvt.oBtn
'.Style = msoButtonIconAndWrapCaption
.Style = msoButtonIconAndCaption
.Caption = cBtnCaption
.Tag = cBtnTag
.FaceId = cBtnFaceID
End With
oBtns.Add oEvt
End Function
Function myAddIn_removeCommandBar(ByVal cCBname As String)
Dim cb As CommandBar
For Each cb In Application.VBE.CommandBars
If cb.Name = cCBname Then
Application.VBE.CommandBars.Item(cCBname).Delete
Exit Function
End If
Next
End Function
Function myAddIn_buttonClick(ByVal cBtnTag As String)
MsgBox ("You clicked: " & cBtnTag)
End Function
' die wird nie aufgerufen
Public Sub AddinInstance_OnConnection(ByVal _
Application As Object, ByVal ConnectMode As _
AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst _
As Object, custom() As Variant)
MsgBox ("TEST!")
End Sub
--------------------------------------
Klassenmodul 'cls_myAddIn_ButtonEvents':
--------------------------------------
Public WithEvents oBtn As CommandBarButton
Private Sub oBtn_click(ByVal ctrl As Office.CommandBarButton, CancelDefault
As Boolean)
DCode_buttonClick ctrl.Tag
End Sub
---------------------------
Tabelle uSysRegInfo:
---------------------------
Subkey;Type;ValName;Value
HKEY_CURRENT_ACCESS_PROFILE\Menu Add-ins\&myAddin;0;;
HKEY_CURRENT_ACCESS_PROFILE\Menu
Add-ins\&myAddin;1;Library;|ACCDIR\myAddin.mda
HKEY_CURRENT_ACCESS_PROFILE\Menu
Add-ins\&myAddin;1;Expression;=myAddin_start()
HKEY_CURRENT_ACCESS_PROFILE\Menu Add-ins\&myAddin;1;Version;3
---------------------------
kläglicher Versuch eines zusätzlichen Klassenmoduls, wie wird das dann
angesprochen?
---------------------------
Option Compare Database
Option Explicit
Implements AddInDesignerObjects.IDTExtensibility2
Public appHostApp As Application
Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
' not used but required by Implements.
MsgBox ("Hallohallo1")
End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
' keep this
End Sub
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)
Set appHostApp = Application
'Set ThisCAI = AddInInst
'Set ExcelEvents = New CExcelEvents
MsgBox ("Hallohallo2")
End Sub
Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As
AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
Set appHostApp = Nothing
'Set ThisCAI = Nothing
'Set ExcelEvents = Nothing
MsgBox ("Hallohallo3")
End Sub
Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
'keep this
End Sub