Home > Archive > Visual Basic Addins > November 2005 > Problems with a Word Toolbar add-in using VB
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Problems with a Word Toolbar add-in using VB
|
|
| Suzette 2005-11-21, 9:58 pm |
| I am trying to build a Word add in using the information in MSDN at:
http://msdn.microsoft.com/library/d...tml/ivb0085.asp
I am using VB6 and Word 2003 (Word 11 library)
I completed it. I compiled it and started the DLL in the VB IDE. When I
open Word I can see it in the COM Add-Ins but it does not create the toolbar
or anything. I tried adding a messagebox in the OnConnection event of the
AddinInstance to see if it was getting that far. NOthing happened. I'm a
bit . Following is the code I have. I even tried copying it
directly from the web page thinking I missed something. A word of advice
would be appreciated.
Thank you
Option Explicit
Public FormDisplayed As Boolean
Public OfficeApp As Object
Dim mcbMenuCommandBar As Office.CommandBar
Dim WithEvents mcbMenuButton As Office.CommandBarButton
Dim mfrmAddIn As New frmAddIn
' Constants for characters surrounding ProgID.
Const PROG_ID_START As String = "!<"
Const PROG_ID_END As String = ">"
' Constants for menu item in an Office application.
Const CBR_NAME As String = "Tools"
Const CTL_CAPTION As String = "&Repeat Phrases"
Const CTL_KEY As String = "RepeatPhrases"
Const CTL_NAME As String = "Repeat Word Phrases"
Private Sub AddinInstance_OnConnection(ByVal _
Application As Object, ByVal
ConnectMode As _
AddInDesignerObjects.ext_ConnectMode,
ByVal _
AddInInst As Object, custom() As
Variant)
On Error GoTo error_handler
MsgBox "Connected"
Set OfficeApp = Application
If ConnectMode = ext_cm_External Then
'Used by the wizard toolbar to start this wizard
Me.Show
Else
Set mcbMenuButton = CreateAddInCommandBarButton _
(OfficeApp, ConnectMode, AddInInst)
End If
If ConnectMode = ext_cm_AfterStartup Then
If GetSetting(App.Title, "Settings", _
"DisplayOnConnect", "0") = "1" Then
'set this to display the form on connect
Me.Show
End If
End If
Exit Sub
error_handler:
MsgBox Err.Description
End Sub
'------------------------------------------------------
'this method removes the Add-In from VB
'------------------------------------------------------
Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode _
As AddInDesignerObjects.ext_DisconnectMode,
custom() As Variant)
On Error Resume Next
' Replace the above line with the following 2 lines
mcbMenuButton.Delete
Set mcbMenuButton = Nothing
'shut down the Add-In
If FormDisplayed Then
SaveSetting App.Title, "Settings", "DisplayOnConnect", "1"
FormDisplayed = False
Else
SaveSetting App.Title, "Settings", "DisplayOnConnect", "0"
End If
Unload mfrmAddIn
Set mfrmAddIn = Nothing
End Sub
Private Sub AddinInstance_OnStartupComplete(custom()
As Variant)
If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
'set this to display the form on connect
Me.Show
End If
End Sub
'this event fires when the menu is clicked in the IDE
Private Sub MenuHandler_Click(ByVal CommandBarControl As Object, handled As
Boolean, CancelDefault As Boolean)
Me.Show
End Sub
Function CreateAddInCommandBarButton(ByVal _
Application As Object, ByVal ConnectMode As _
AddInDesignerObjects.ext_ConnectMode, ByVal _
AddInInst As Object) As Office.CommandBarButton
Dim cbrMenu As Office.CommandBar
Dim ctlBtnAddIn As Office.CommandBarButton
On Error GoTo CreateAddInCommandBarButton_Err
' Return reference to command bar.
Set cbrMenu = Application.CommandBars(CBR_NAME)
Set ctlBtnAddIn = cbrMenu.FindControl(Tag:=CTL_KEY)
If ctlBtnAddIn Is Nothing Then
Set ctlBtnAddIn = cbrMenu.Controls.Add _
(Type:=msoControlButton, Parameter:=CTL_KEY)
With ctlBtnAddIn
.Caption = CTL_CAPTION
.Tag = CTL_KEY
.Style = msoButtonCaption
' Use AddInInst argument to return reference
' to this add-in.
.OnAction = PROG_ID_START & AddInInst.ProgId _
& PROG_ID_END
End With
End If
Set CreateAddInCommandBarButton = ctlBtnAddIn
Set ctlBtnAddIn = Nothing
Set cbrMenu = Nothing
Exit Function
CreateAddInCommandBarButton_Err:
MsgBox Err.Description
End Function
Private Sub mcbMenuButton_Click(ByVal Ctrl _
As Office.CommandBarButton, CancelDefault _
As Boolean)
Call Show
End Sub
Sub Hide()
On Error Resume Next
FormDisplayed = False
mfrmAddIn.Hide
End Sub
Sub Show()
On Error Resume Next
Set mfrmAddIn.RepeatAddin = Me
FormDisplayed = True
mfrmAddIn.Show
End Sub
| |
| Jan Hyde 2005-11-22, 4:01 am |
| "Suzette" <anon@hotmail.com>'s wild thoughts were released
on Mon, 21 Nov 2005 19:16:43 -0800 bearing the following
fruit:
>I am trying to build a Word add in using the information in MSDN at:
>http://msdn.microsoft.com/library/d...tml/ivb0085.asp
>
>I am using VB6 and Word 2003 (Word 11 library)
>
>I completed it. I compiled it and started the DLL in the VB IDE. When I
>open Word I can see it in the COM Add-Ins but it does not create the toolbar
>or anything. I tried adding a messagebox in the OnConnection event of the
>AddinInstance to see if it was getting that far. NOthing happened. I'm a
>bit . Following is the code I have. I even tried copying it
>directly from the web page thinking I missed something. A word of advice
>would be appreciated.
I wonder if you have a compiled version of the DLL on your
PC? I find I sometimes need to unregister any compiled
version for (in my case) outlook to link to my IDE version.
J
>Thank you
>
>Option Explicit
> Public FormDisplayed As Boolean
> Public OfficeApp As Object
> Dim mcbMenuCommandBar As Office.CommandBar
> Dim WithEvents mcbMenuButton As Office.CommandBarButton
> Dim mfrmAddIn As New frmAddIn
>
> ' Constants for characters surrounding ProgID.
> Const PROG_ID_START As String = "!<"
> Const PROG_ID_END As String = ">"
>
> ' Constants for menu item in an Office application.
> Const CBR_NAME As String = "Tools"
> Const CTL_CAPTION As String = "&Repeat Phrases"
> Const CTL_KEY As String = "RepeatPhrases"
> Const CTL_NAME As String = "Repeat Word Phrases"
>
> Private Sub AddinInstance_OnConnection(ByVal _
> Application As Object, ByVal
>ConnectMode As _
> AddInDesignerObjects.ext_ConnectMode,
>ByVal _
> AddInInst As Object, custom() As
>Variant)
> On Error GoTo error_handler
> MsgBox "Connected"
>
> Set OfficeApp = Application
> If ConnectMode = ext_cm_External Then
> 'Used by the wizard toolbar to start this wizard
> Me.Show
> Else
> Set mcbMenuButton = CreateAddInCommandBarButton _
> (OfficeApp, ConnectMode, AddInInst)
> End If
>
> If ConnectMode = ext_cm_AfterStartup Then
> If GetSetting(App.Title, "Settings", _
> "DisplayOnConnect", "0") = "1" Then
> 'set this to display the form on connect
> Me.Show
> End If
> End If
>
> Exit Sub
>error_handler:
> MsgBox Err.Description
> End Sub
>
>
>'------------------------------------------------------
>'this method removes the Add-In from VB
>'------------------------------------------------------
>Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode _
> As AddInDesignerObjects.ext_DisconnectMode,
>custom() As Variant)
> On Error Resume Next
>
>' Replace the above line with the following 2 lines
>mcbMenuButton.Delete
> Set mcbMenuButton = Nothing
>
> 'shut down the Add-In
> If FormDisplayed Then
> SaveSetting App.Title, "Settings", "DisplayOnConnect", "1"
> FormDisplayed = False
> Else
> SaveSetting App.Title, "Settings", "DisplayOnConnect", "0"
> End If
>
> Unload mfrmAddIn
> Set mfrmAddIn = Nothing
>
>End Sub
>
>Private Sub AddinInstance_OnStartupComplete(custom()
As Variant)
> If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
> 'set this to display the form on connect
> Me.Show
> End If
>End Sub
>
>'this event fires when the menu is clicked in the IDE
>Private Sub MenuHandler_Click(ByVal CommandBarControl As Object, handled As
>Boolean, CancelDefault As Boolean)
> Me.Show
>End Sub
>
>Function CreateAddInCommandBarButton(ByVal _
> Application As Object, ByVal ConnectMode As _
> AddInDesignerObjects.ext_ConnectMode, ByVal _
> AddInInst As Object) As Office.CommandBarButton
> Dim cbrMenu As Office.CommandBar
> Dim ctlBtnAddIn As Office.CommandBarButton
>
> On Error GoTo CreateAddInCommandBarButton_Err
> ' Return reference to command bar.
> Set cbrMenu = Application.CommandBars(CBR_NAME)
> Set ctlBtnAddIn = cbrMenu.FindControl(Tag:=CTL_KEY)
> If ctlBtnAddIn Is Nothing Then
> Set ctlBtnAddIn = cbrMenu.Controls.Add _
> (Type:=msoControlButton, Parameter:=CTL_KEY)
> With ctlBtnAddIn
> .Caption = CTL_CAPTION
> .Tag = CTL_KEY
> .Style = msoButtonCaption
> ' Use AddInInst argument to return reference
> ' to this add-in.
> .OnAction = PROG_ID_START & AddInInst.ProgId _
> & PROG_ID_END
> End With
> End If
>
> Set CreateAddInCommandBarButton = ctlBtnAddIn
> Set ctlBtnAddIn = Nothing
> Set cbrMenu = Nothing
>
> Exit Function
>CreateAddInCommandBarButton_Err:
> MsgBox Err.Description
> End Function
>
>Private Sub mcbMenuButton_Click(ByVal Ctrl _
> As Office.CommandBarButton, CancelDefault _
> As Boolean)
> Call Show
> End Sub
>
>Sub Hide()
> On Error Resume Next
> FormDisplayed = False
> mfrmAddIn.Hide
>End Sub
>
>Sub Show()
> On Error Resume Next
> Set mfrmAddIn.RepeatAddin = Me
> FormDisplayed = True
> mfrmAddIn.Show
>End Sub
>
>
Jan Hyde (VB MVP)
--
Have you heard about the downhill skier who was an exhibitionist?
He was arrested for in-descent exposure. (Richard Lederer)
[Abolish the TV Licence - http://www.tvlicensing.biz/]
| |
| Suzette 2005-11-22, 7:04 pm |
| I doubt it because the dll developed through the sample is called
repeatphrase.dll. Nothing else like that around. Nice thought though.
"Jan Hyde" <StellaDrinker@REMOVE.ME.uboot.com> wrote in message
news:gvo5o11b7pbu7hsug3fj810cg56tp89u5m@
4ax.com...
> "Suzette" <anon@hotmail.com>'s wild thoughts were released
> on Mon, 21 Nov 2005 19:16:43 -0800 bearing the following
> fruit:
>
>
> I wonder if you have a compiled version of the DLL on your
> PC? I find I sometimes need to unregister any compiled
> version for (in my case) outlook to link to my IDE version.
>
> J
>
>
>
> Jan Hyde (VB MVP)
>
> --
> Have you heard about the downhill skier who was an exhibitionist?
> He was arrested for in-descent exposure. (Richard Lederer)
>
> [Abolish the TV Licence - http://www.tvlicensing.biz/]
>
| |
| Jan Hyde 2005-11-23, 3:58 am |
| "Suzette" <anon@hotmail.com>'s wild thoughts were released
on Tue, 22 Nov 2005 11:41:28 -0800 bearing the following
fruit:
>I doubt it because the dll developed through the sample is called
>repeatphrase.dll. Nothing else like that around. Nice thought though.
The easy way to know is to run word without your project
loaded. If the addin is available then you must have a
compiled version somewhere.
Another thing to check, what is the 'Inital Load Behavour'
setting?
J
>"Jan Hyde" <StellaDrinker@REMOVE.ME.uboot.com> wrote in message
> news:gvo5o11b7pbu7hsug3fj810cg56tp89u5m@
4ax.com...
>
Jan Hyde (VB MVP)
--
Handkerchief: Cold storage. (John Nunley)
[Abolish the TV Licence - http://www.tvlicensing.biz/]
| |
| Suzette 2005-11-23, 7:03 pm |
| It doesn't show up unless I have it running in the IDE and the "Initial Load
Behavior" is Load at Startup so it is loading but I'll be darned if I can
figure out why it's not doing anything. I'm doing more research today so if
I figure anything out, I'll post. Thanks for your help.
> Another thing to check, what is the 'Inital Load Behavour'
> setting?
>
> J
>
|
|
|
|
|