Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word toolbar - locking them down from Users

Status
Not open for further replies.

ckpeel

Technical User
Jan 4, 2002
20
CA
hi

This I hope is an easy answer.... but I haven't been able to figure out how
to do this.

I have a Word addin that I need a tool bar for ... I created code to add the
toolbar and it works fine... I added it to the AutoExec routine. So when
the addin is loaded I check for the tool bar and if it's not there I creat
it. On unload I remove the addin.

Problem one: It seems that through this code the toolbar is added to the
normal template? Because when I unload the template or if the user should
remove the .dot file without unloading the a new toolbar appears in the
normal.dot file. I can't remove the toolbar without over-writing the
normal.dot file?

Question: How can I insure the toolbar is only added to the .dot file (or my
addin).

Whatelse I tried to do:

After playing with all kinds of tricks I decided to just add the tool bar
into the doc file and save it as a dot file. This seems to work but exposed
one problem.....

If the user is silly enough to 'delete the custom toolbar' it gets removed
from the addin (.dot file). When the user closes Word you get prompted to
save changes in the addin. If they say yes they loose the addin toolbar and
can't get it back (easily).


So question are:

1. How can I via code add or make sure I have the toolbar I need but it has
to be attached to the .dot file (not the normal.dot file)?
2. If I have a toolbar in an addin how do I stop the user from deleting it?

note: I tried setting the protection on the toolbar but it doesn't stop you
from deleting a toolbar

Please any help appreciated......

Chris.

 
Could you post a short, edited version of the code you use to create and delete the toolbar?
Rob
[flowerface]
 
Sure.. this is the code I use to construct the Toolbars:


Function fCreateAvistaToolbar() as Boolean

'====================================
Dim cbrCmdBar As CommandBar
Dim strCBarName As String

Dim sSubName As String 'current Subname we are in

On Error GoTo Err_fCreateAvistaToolbar


'=====================================================
' *** CODE ****
'=====================================================
'check if toolbar already exists

If Not fChkAvistToolBar Then

'create tool bar
strCBarName = ToolBarName
Set cbrCmdBar = Application.CommandBars.add(strCBarName, msoBarTop)

cbrCmdBar.Visible = True

'make sure users can't change or hide the toolbar
'cbrCmdBar.Protection = msoBarNoChangeVisible + msoBarNoCustomize

'create buttons on bar

With cbrCmdBar.Controls.add
.Caption = "Avista"
.DescriptionText = "Launch Avista Main Dialog"
.TooltipText = "Launch Avista Office Integration"
.OnAction = "Main.OpenMainDialog"
End With


'copy image over now - using hidden toolbar as image holder

CommandBars("ASC_ToolBarImages").Controls("Avista").CopyFace

CommandBars(ToolBarName).Controls(1).PasteFace

ThisDocument.Saved = True

cbrCmdBar.Visible = True
End If


'=======================================================================
fCreateAvistaToolbar = True

Command_Exit:
Exit Function ' end sub/function

'=============================================================================
Err_fCreateAvistaToolbar:

'log error message into log
fCreateAvistaToolbar = False
Call Functions.wrtLog(Err.Description & "::" & Err.Number, "ERR")
Resume Command_Exit 'exit sub routine

End Function




Private Function fChkAvistToolBar() As Boolean
'========================================================
' SubName: fChkAvistToolBar
'
' Description:
' Check that the Avista Toolbar exists
'
' Requirements: ToolBarName constant is set
'
' Input/Outputs: true if we find toolbar
'
'
' Created by: Christian Peel
' Created Date: Feb 25th, 2003
' --------------------------------------------------------
' Revisions
'
' By: Christian Peel
' Date: Feb 28, 2003
' Description: if the addin isn't loaded on startup the
' old toolbar hangs around - so multiple toolbars
' could result - check for this and insure only one hangs
' around at any time.
'
'=========================================================

On Error GoTo err_fChkAvistToolBar

Dim cmdBar As CommandBar
Dim iBarCount As Integer

'======================================================
' *** CODE ****
'======================================================
fChkAvistToolBar = False

iBarCount = 0

For Each cmdBar In CommandBars
If cmdBar.Name = ToolBarName Then
cmdBar.Visible = True
cmdBar.Protection = msoBarNoCustomize + msoBarNoChangeVisible
fChkAvistToolBar = True
iBarCount = iBarCount + 1
If iBarCount > 1 Then
If LogFlag Then _
cmdBar.Delete 'remove any bars above the first one
End If
End If
Next cmdBar

Exit Function

err_fChkAvistToolBar:

'error occured - return false
fChkAvistToolBar = False

End Function
 
Sorry - been away for a few days... the code for delete is as follows:

Dim rc As Variant ' general Return code variable

On Error GoTo Err_fDeleteAvistaToolbar 'should be err_subname where sub name is the function
'sub name we are in.

'=======================================================================
' *** CODE ****
'=======================================================================

Dim cmdBar As CommandBar

For Each cmdBar In CommandBars
If cmdBar.Name = ToolBarName Then
cmdBar.Delete
If LogFlag Then Call Functions.wrtLog(vbTab & _
"ASC_ToolBar::fDeleteAvistaToolbar::Deleted Avista Toolbar", "INFO")
End If
fDeleteAvistaToolbar = True
Next

Exit Function

Err_fDeleteAvistaToolbar:
fDeleteAvistaToolbar = False
End Function
 
Sorry for the delay in response. What I meant was, where is this code called? When is the toolbar deleted?
Rob
[flowerface]
 
I call the code from the following sub:

Sub AutoExec()
'Code that checks for the toolbar and adds
' it if required
End Sub

Sub AutoExit()
'delete the toolbar on unload
'routines run on unload of addin
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top