R
RB Smissaert
Just started to learn COM add-ins with Office XP and Office XP developer.
One strange, but interesting thing I noted is that I can make a VBA userform
with a minimize and maximize button without using any Windows API.
This is what I have:
A very simple .vba project with the following modules:
a normal VBA userform, only holding a label with caption with the following
code:
----------------------------------------------------------------------------
----------------------
Option Explicit
Private Sub UserForm_Activate()
Me.BackColor = RGB(221, 230, 228)
End Sub
A normal code module with the following code:
--------------------------------------------------------
Option Explicit
Public appHostApp As Application
Public gAddInInst As Object
Public Const PROG_ID_START As String = "!<"
Public Const PROG_ID_END As String = ">"
Public MenuEvents As CMenuEvents
A Class module with the following code:
------------------------------------------------
Option Explicit
Private WithEvents btnMenuItem1 As Office.CommandBarButton
Friend Sub CreateMenuItems()
With appHostApp.CommandBars.ActiveMenuBar.Controls("Tools").Controls
Set btnMenuItem1 = .Add
With btnMenuItem1
.Caption = "Load Form"
.OnAction = PROG_ID_START & gAddInInst.progID & PROG_ID_END
.BeginGroup = True
End With
End With
End Sub
Friend Sub DeleteMenuItems()
On Error Resume Next
btnMenuItem1.Delete
End Sub
Private Sub btnMenuItem1_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)
UserForm1.Show vbModeless
End Sub
A add-in designer module with the following code:
------------------------------------------------------------
Option Explicit
Implements IDTExtensibility2
Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As
AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, _
custom() As Variant)
'Store startup reference
Set appHostApp = Application
Set gAddInInst = AddInInst
Set MenuEvents = New CMenuEvents
MenuEvents.CreateMenuItems
End Sub
Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As
AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
If RemoveMode = ext_dm_UserClosed Then
MenuEvents.DeleteMenuItems
End If
'remove references to shutdown
Set appHostApp = Nothing
End Sub
That is all.
Now I have no idea why the VBA userform has these extra buttons.
the only line of code I could think of is this one:
.OnAction = PROG_ID_START & gAddInInst.progID & PROG_ID_END
Thanks for any insight in this.
RBS
One strange, but interesting thing I noted is that I can make a VBA userform
with a minimize and maximize button without using any Windows API.
This is what I have:
A very simple .vba project with the following modules:
a normal VBA userform, only holding a label with caption with the following
code:
----------------------------------------------------------------------------
----------------------
Option Explicit
Private Sub UserForm_Activate()
Me.BackColor = RGB(221, 230, 228)
End Sub
A normal code module with the following code:
--------------------------------------------------------
Option Explicit
Public appHostApp As Application
Public gAddInInst As Object
Public Const PROG_ID_START As String = "!<"
Public Const PROG_ID_END As String = ">"
Public MenuEvents As CMenuEvents
A Class module with the following code:
------------------------------------------------
Option Explicit
Private WithEvents btnMenuItem1 As Office.CommandBarButton
Friend Sub CreateMenuItems()
With appHostApp.CommandBars.ActiveMenuBar.Controls("Tools").Controls
Set btnMenuItem1 = .Add
With btnMenuItem1
.Caption = "Load Form"
.OnAction = PROG_ID_START & gAddInInst.progID & PROG_ID_END
.BeginGroup = True
End With
End With
End Sub
Friend Sub DeleteMenuItems()
On Error Resume Next
btnMenuItem1.Delete
End Sub
Private Sub btnMenuItem1_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)
UserForm1.Show vbModeless
End Sub
A add-in designer module with the following code:
------------------------------------------------------------
Option Explicit
Implements IDTExtensibility2
Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As
AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, _
custom() As Variant)
'Store startup reference
Set appHostApp = Application
Set gAddInInst = AddInInst
Set MenuEvents = New CMenuEvents
MenuEvents.CreateMenuItems
End Sub
Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As
AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
If RemoveMode = ext_dm_UserClosed Then
MenuEvents.DeleteMenuItems
End If
'remove references to shutdown
Set appHostApp = Nothing
End Sub
That is all.
Now I have no idea why the VBA userform has these extra buttons.
the only line of code I could think of is this one:
.OnAction = PROG_ID_START & gAddInInst.progID & PROG_ID_END
Thanks for any insight in this.
RBS