Hi Kauser
I will reproduce the code I used to create the toolbars and open the
documents, some of the code references other classes which I have not
reproduced here. However these are generally speaking dataaccess classes,
which will not be relevant for this example. I set this up as a module, but
it could be added to a class or I suppose directly in the connect.vb.
As to the action pane, I am using this so that the user can add data to the
templates once they have been opened, such as addresses, signatures,
telephone numbers etc.. this is retreived from a seperate contacts database.
However in your original post you mentioned using an action pane to open the
documents, so I have also included some code at the bottom of this post which
will allow you to add a user defined task pane to a document.
I hope that this prooves useful
Cheers
Richard
TOOLBAR CODE
Imports Microsoft.Office.Core
Module modWord
' Declare the menu variable at the class level.
Private cDocs As New BLL.clsDocuments
'Creates an array of base toolbar buttons, these are to be set up as
popup style controls
Dim cbButton(6) As CommandBarControl
'Creates an array of toolbar buttons - to be added to the main drop down
buttons
Private btn(50) As CommandBarButton
Dim cb As CommandBar
'declares Word Application
Private wApp As Microsoft.Office.Interop.Word.Application
Dim intIndex As Integer = 0
Sub CreateMenu(ByVal applicationObject As
Microsoft.Office.Interop.Word.Application)
'Creates Office Toolbar
Dim strMenuName As String = "Custom Tools"
wApp = applicationObject
cb = wApp.CommandBars.Add(strMenuName, 1, False, True)
'Creates the 4 main toolbar buttons, all other buttons will be drop
down buttons,
'attached to these.
cbButton(1) = cb.Controls.Add(MsoControlType.msoControlPopup, , , ,
True)
cbButton(2) = cb.Controls.Add(MsoControlType.msoControlPopup, , , ,
True)
cbButton(3) = cb.Controls.Add(MsoControlType.msoControlPopup, , , ,
True)
cbButton(4) = cb.Controls.Add(MsoControlType.msoControlPopup, , , ,
True)
'Set button properties
With cbButton(1)
.Caption = "&Letters && Faxes"
.Tag = "Letters"
.BeginGroup = False
End With
With cbButton(2)
.Caption = "&Other Documents"
.Tag = "Other Documents"
.BeginGroup = False
End With
With cbButton(3)
.Caption = "&Printing Options"
.Tag = "Printing Options"
.BeginGroup = False
End With
With cbButton(4)
.Caption = "&London Print"
.Tag = "London Options"
.BeginGroup = False
End With
'Create dataset which will hold the information to build the
'drop down items.
Dim dsCommandBarItems As New DataSet
Dim intLooper As Integer = 1
'Loop through the database and extract information for each
'drop down toolbar button.
For intLooper = 1 To 4
'Reference Class to retreive data from database
dsCommandBarItems = cDocs.CreateCommandBar(intLooper)
Dim intLoop As Integer
With dsCommandBarItems.Tables(0)
'For each document in database, retrieves the document info
'and passes it to the method to create the toolbar button
For intLoop = 0 To .Rows.Count - 1
AddButton(.Rows(intLoop).Item("Caption").ToString, _
CInt(.Rows(intLoop).Item("Image").ToString), _
cbButton(intLooper),
CInt(.Rows(intLoop).Item("DocumentID").ToString), _
CBool(.Rows(intLoop).Item("BeginGroup").ToString))
intIndex += 1
Next
End With
Next
cb.Visible = True
cb = Nothing
End Sub
Private Sub ButtonClick(ByVal ctrl As CommandBarButton, ByRef Cancel As
Boolean)
Try
'Opens Document - passes documentID to database, which in turn
returns the path to the document
wApp.Documents.Add(cDocs.GetDocumentPath(CInt(ctrl.Tag)))
Catch ex As Exception
MsgBox("Word was unable to open the document, check that the
document exists and try again", MsgBoxStyle.Information, "Template Error")
End Try
End Sub
Private Sub AddButton(ByVal strCaption As String, ByVal intFaceID As
Integer, ByVal objCommandBar As Object, ByVal intDocumentID As Integer, ByVal
bhasGroup As Boolean)
btn(intIndex) =
CType(objCommandBar.Controls.Add(MsoControlType.msoControlButton),
CommandBarButton)
With btn(intIndex)
'Sets toolbar button caption
.Caption = strCaption
'Sets toolbar button image
.FaceId = intFaceID
'Set toolbar tag to = document ID, will be used later to
retreive document path from database
.Tag = Str(intDocumentID)
'Set the begingroup variable
.BeginGroup = bhasGroup
End With
'Adds handler for the toolbar.button click event
AddHandler btn(intIndex).Click, AddressOf ButtonClick
End Sub
End Module
ACTION PANE CODE
'Adds a reference to the user control
Imports WindowsControlLibrary1
Public Class ThisDocument
Private WithEvents ucTaskPane As TaskPane
Private Sub ThisDocument_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
ucTaskPane = New TaskPane(Me)
Me.ActionsPane.Controls.Add(ucTaskPane)
End Sub
End Class
Kausar Parveen - 05 Apr 2006 13:19 GMT
Hello Richard,
Thanks a lot for your instant reply and that too positive:-) Let me
checkout your code and i'll get back to you.
Best Regards
Kausar
> Hi Kauser
>
[quoted text clipped - 149 lines]
>
> End Class