Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Menus and Toolbars / April 2005

Tip: Looking for answers? Try searching our database.

Deleted WordXP toolbars will not stay deleted

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richard.D.White@irs.gov - 06 Apr 2005 13:49 GMT
I have a WordXP custom built toolbar problem. I wrote VBA code that
builds a custom Word toolbar. When I ran the code, the toolbar was
created and worked fine. When I needed to update the toolbar, I made
the VBA code changes, deleted the toolbar manually, and then ran the
code. The toolbar appears to be created correctly. The problem is when
I exit Word and then later start Word again, there are two instances of
the toolbar. Why didn't the first instance I deleted stay deleted? I
also have code to delete the toolbar before rebuilding it.

A portion of the code lies below. The code worked okay until I upgraded
to OfficeXP Pro. Is this a 'feature' of WordXP?

Thanks for any assistance/insight.

   Dim objCommandBar As office.CommandBar
   Dim objCommandBarControl As office.CommandBarControl
   Dim objCommandBarButton As office.CommandBarButton
   Dim objCommandBarComboBox As office.CommandBarComboBox
   Dim objCommandBarPopup As office.CommandBarPopup
   Dim objCommandBarPopup2 As office.CommandBarPopup

   Dim cbToolBar As CommandBar
   Dim cbMenuBar As CommandBarPopup
   Dim cbSuBMnu1 As CommandBarButton
   Dim cbSuBMnu2 As CommandBarPopup
   Dim cbSuBMnu2_PopUp As CommandBarButton
   Dim cbSuBMnu3 As CommandBarPopup
   Dim strToolbar As String
   Dim iCount As Integer

   Dim str1 As String
   Dim str2 As String
   Dim strCaption As String
   Dim strAction As String
   Dim strDesc As String
   Dim lngFaceId As Long

   Dim cbb8 As office.CommandBarButton
   Dim cbb9 As office.CommandBarButton
   Dim cbc8 As office.CommandBarControl
   Dim cbc9 As office.CommandBarControl
   Dim cbar1 As office.CommandBar
   Dim cbar9 As office.CommandBar
   Dim cbrp1 As office.CommandBarPopup

'----------------------------------------------------------
' Created by Dick White on 12/3/2002
' Purpose: Create standard toolbar
' Inputs:
' Outputs:
'----------------------------------------------------------
Sub sCmdToolBarMyToolbar_XP()
   On Error GoTo E_Handle
   Dim lngID As Long

   strToolbar = "MyToolbar OfcXP"

   'delete existing toolbar
   For Each objCommandBar In Application.CommandBars
       With objCommandBar
           If .BuiltIn = False Then
               If objCommandBar.Name = strToolbar Then
                   objCommandBar.Delete
                   MsgBox "Deleted toolbar"
                   Exit For
               End If
           End If
       End With
   Next objCommandBar

   '====================
   'deletes any previously created custom toolbars and rebuilds
'    Dim ctrlControl As office.CommandBar
'    For Each ctrlControl In Application.CommandBars("Menu
Bar").Controls
'        If ctrlControl.Caption = "My Main Menu &Name" Then
'            ctrlControl.Delete
'            Exit For
'        End If
'    Next ctrlControl
   '====================

   Application.CommandBars.DisplayTooltips = True

   'create toolbar
   Set objCommandBar = Application.CommandBars.Add _
       (strToolbar)

   objCommandBar.Position = msoBarTop
   objCommandBar.RowIndex = msoBarRowLast
   objCommandBar.Left = 0

   With objCommandBar.Controls

       '-------------------------

       'set up label button
       Set objCommandBarButton = .Add(msoControlButton)
       strAction = ""
       strCaption = strToolbar
       strDesc = strCaption
       Call sBldCmdBarCtlBtnIcon(objCommandBarButton, strAction,
strCaption, strDesc, True, 28)

       '-------------------------

       'set up  button
       Set objCommandBarButton = .Add(msoControlButton)
       strCaption = "GetDocInfo"
       strDesc = strCaption
       strAction = "GetDocInfo"
       Call sBldCmdBarCtlBtnIcon(objCommandBarButton, strAction,
strCaption, strDesc, True)

       '-------------------------

       'set up builtin button for properties
'        Set cbrp1 = objCommandBarPopup
       Set cbb8 = objCommandBarButton
       lngID = 750 'Properties
       Set cbc9 = fFindCtrl(lngID)
       With cbc9
           .Copy Bar:=objCommandBar
       End With
       Set objCommandBarControl = objCommandBar.FindControl(ID:=lngID)
       objCommandBarControl.BeginGroup = True

       '=====================================

       'set up  popup button
       Set objCommandBarPopup = .Add(msoControlPopup)
       With objCommandBarPopup

           .Caption = "Save"
           strDesc = strCaption
           strAction = ""
           .BeginGroup = True
           objCommandBarPopup.BeginGroup = True

           '-------------------------

           'set up  button
           Set objCommandBarButton = .Controls.Add(msoControlButton)
           strCaption = "Save as Doc"
           strDesc = strCaption
           strAction = "sSaveAsDoc"
           Call sBldCmdBarCtlBtnIcon(objCommandBarButton, strAction,
strCaption, strDesc, True)
           objCommandBarButton.BeginGroup = True

           '-------------------------

           'set up  button
           Set objCommandBarButton = .Controls.Add(msoControlButton)
           strCaption = "Save as Text"
           strDesc = strCaption
           strAction = "sSaveAsText"
           Call sBldCmdBarCtlBtnIcon(objCommandBarButton, strAction,
strCaption, strDesc, True)
           objCommandBarButton.BeginGroup = True

           '-------------------------

           'set up  button
           Set objCommandBarButton = .Controls.Add(msoControlButton)
           strCaption = "Save as RTF"
           strDesc = strCaption
           strAction = "sSaveRTF"
           Call sBldCmdBarCtlBtnIcon(objCommandBarButton, strAction,
strCaption, strDesc, True)
           objCommandBarButton.BeginGroup = True

           '-------------------------

           'set up  button
           Set objCommandBarButton = .Controls.Add(msoControlButton)
           strCaption = "Save as Temp.doc"
           strDesc = strCaption
           strAction = "sSaveAsTemp"
           Call sBldCmdBarCtlBtnIcon(objCommandBarButton, strAction,
strCaption, strDesc, True)
           objCommandBarButton.BeginGroup = True

           '-------------------------

       End With

       '=====================================

       '-------------------------

       'set up  button
       Set objCommandBarButton = .Add(msoControlButton)
       strCaption = "Quit"
       strDesc = strCaption
'        strAction = "sQuit"
       strAction = "sQuit"
       Call sBldCmdBarCtlBtnIcon(objCommandBarButton, strAction,
strCaption, strDesc, True)

   End With

   '=====================================

sExit:
   On Error Resume Next
   Set objCommandBarButton = Nothing
   Set objCommandBarPopup = Nothing
   Set objCommandBarComboBox = Nothing
   Set cbSuBMnu2 = Nothing
   Set cbSuBMnu3 = Nothing
   Set cbSuBMnu2_PopUp = Nothing
   objCommandBar.Visible = True
   Exit Sub

E_Handle:
'    MsgBox Err.Description & vbCrLf & "sCmdToolBarMyToolbar_XP",
vbOKOnly + vbCritical, "Error: " & Err.Number

   Select Case Err.Number
       Case 91
           'Tell Word to ignore this error and move on to the next
line
           Debug.Print "--error" & vbCrLf & Err.Number & ", " &
Err.Description
           Resume Next
       Case 438
           'Tell Word to ignore this error and move on to the next
line
           Resume Next
       Case Else
           'Pop up a message box with the error and exit the Procedure
           MsgBox "Error " & Err.Number & ", " & Err.Description
           Debug.Print "--error" & vbCrLf & Err.Number & ", " &
Err.Description
'            Debug.Print cbc.Type, cbc.ID, cbc.Caption
   End Select

   Resume sExit

End Sub
Cindy M  -WordMVP- - 08 Apr 2005 19:55 GMT
> I have a WordXP custom built toolbar problem. I wrote VBA code that
> builds a custom Word toolbar. When I ran the code, the toolbar was
[quoted text clipped - 7 lines]
> A portion of the code lies below. The code worked okay until I upgraded
> to OfficeXP Pro. Is this a 'feature' of WordXP?

I didn't go through all your code, but a quick scan doesn't reveal you
setting the CustomizationContext anywhere. If you don't specify that,
Word can end up creating the toolbar just about anywhere... So, what you
thought you deleted may not actually be deleted, because it wasn't stored
where you were doing the deleting.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
Dick - 11 Apr 2005 12:55 GMT
Cindy,

Thank you for your response. I tried your suggestion and unfortunately
the duplicate toolbars still exist. Based on your suggestion I wrote
the following code to delete any instances of the toolbar. After
running it, I exited Word and then restarted Word. After restarting,
Word displayed two instances of the toolbar. Can you suggest anything
else?

Dick

************* Code Start
'----------------------------------------------------------
' Created by Dick White on 4/11/2005
' Purpose: delete all instances of toolbar: MyToolbar OfcXP
' Inputs:
' Outputs:
'----------------------------------------------------------
Sub sMyXPToolbarDelete()
   On Error GoTo E_Handle
   Dim strMsg As String
   Dim str1 As String
   Dim str2 As String
   Dim rng1 As Range
   Dim lngID As Long
   Dim bTest As Boolean

'    Application.ScreenUpdating = False

   strToolbar = "MyToolbar OfcXP"
'    CustomizationContext = ActiveDocument.AttachedTemplate
   CustomizationContext = NormalTemplate

   bTest = True
   'delete existing toolbar
   Do While bTest
       bTest = False
       For Each objCommandBar In Application.CommandBars
           With objCommandBar
               If .BuiltIn = False Then
                   If objCommandBar.Name = strToolbar Then
                       objCommandBar.Delete
                       MsgBox "Deleted toolbar"
                       bTest = True
                       Exit For
                   End If
               End If
           End With
       Next objCommandBar
   Loop

sExit:
   On Error Resume Next
'    Application.ScreenUpdating = True
   If NormalTemplate.Saved = False Then NormalTemplate.Save
   Exit Sub

E_Handle:
   Select Case Err.Number
       Case 9999999
           'Tell XXX to ignore this error and move on to the next line
           Resume Next
       Case Else
           'Pop up a message box with the error and exit the Procedure
           strMsg = strMsg & vbCrLf & "Error " & Err.Number & ", " &
Err.Description & vbCrLf & "sMyXPToolbarDelete"
'            Call ClipBoard_SetText(strMsg) 'Excel
           Call CopyToClipBoard(strMsg)  'Word
'            Call ClipBoardCopyTo(strMsg) 'PowerPoint
'            Call ClipBoard_SetText(strMsg) 'Access

          MsgBox "Error " & Err.Number & ", " & Err.Description &
vbCrLf & "sMyXPToolbarDelete"
   End Select

   Stop
   Resume sExit

End Sub

************* Code End

Cindy M -WordMVP- wrote:
> > I have a WordXP custom built toolbar problem. I wrote VBA code that
> > builds a custom Word toolbar. When I ran the code, the toolbar was
[quoted text clipped - 10 lines]
> I didn't go through all your code, but a quick scan doesn't reveal you
> setting the CustomizationContext anywhere. If you don't specify that,

> Word can end up creating the toolbar just about anywhere... So, what you
> thought you deleted may not actually be deleted, because it wasn't stored
[quoted text clipped - 7 lines]
> This reply is posted in the Newsgroup; please post any follow question or
> reply in the newsgroup and not by e-mail :-)
Cindy M  -WordMVP- - 12 Apr 2005 15:58 GMT
Hi Dick,

> I tried your suggestion and unfortunately
> the duplicate toolbars still exist. Based on your suggestion I wrote
> the following code to delete any instances of the toolbar. After
> running it, I exited Word and then restarted Word. After restarting,
> Word displayed two instances of the toolbar. Can you suggest anything
> else?

I don't think I really suggested anything...

But what I might try, at this point, would be
   - search my system for Normal.dot; if more than one turns up rename
all except the one I want to use as a global template
   - start Word and see if the second toolbar has disappeared
   - if not, start Word in SAFE MODE and see if the second toolbar is
gone
   - if it is, look for it in templates loading from the STARTUP
folder

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)
Dick - 13 Apr 2005 13:40 GMT
Cindy,

 I tried your suggestions. I searched for instances of the file
NORMAL.DOT. I found two: one was the one I expected; the other was a
smaller one in the Administrator's directory, which I renamed.

 I deleted both instances of the toolbar after executing Word
normally. I exited Word and re-executed it normally. There were two
instances of the toolbar. I exited Word and re-executed Word in Safe
mode. When I viewed the Toolbar list, none of my customized toolbars
were listed, including the one I built with VBA.

 I checked my STARTUP folder(s), but saw nothing I would think would
apply to this issue.

 Thanks for your thoughts and suggestions.

Dick

Cindy M -WordMVP- wrote:
> Hi Dick,
>
[quoted text clipped - 23 lines]
> This reply is posted in the Newsgroup; please post any follow question
> or reply in the newsgroup and not by e-mail :-)
Cindy M  -WordMVP- - 13 Apr 2005 17:29 GMT
Hi Dick,

> I tried your suggestions. I searched for instances of the file
> NORMAL.DOT. I found two: one was the one I expected; the other was a
[quoted text clipped - 8 lines]
>   I checked my STARTUP folder(s), but saw nothing I would think would
> apply to this issue.

SafeMode locks out all global templates, including your Normal.dot. If
you didn't try moving all the *.dot files out of Startup, do that and
boot Word normally to check again. If you're still getting two
toolbars, then the problem is in Normal.dot, and likely at a very deep
level.

In that case, I'd rename Normal.dot so that Word generates a clean
copy. You could then use the Organizer to copy across toolbar, macros
etc.

Ah, that does remind me: you might first try via Tools/Templates and
Addin/Organizer whether you see two of your toolbars, and can delete
one (or both) through that interface.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)
Dick - 14 Apr 2005 19:13 GMT
Cindy,

Your suggestion about the Tools/Addins and the Addin/Organizer worked
like a charm. Thanks.

Dick

Cindy M -WordMVP- wrote:
> Hi Dick,
>
[quoted text clipped - 13 lines]
> SafeMode locks out all global templates, including your Normal.dot. If
> you didn't try moving all the *.dot files out of Startup, do that and

> boot Word normally to check again. If you're still getting two
> toolbars, then the problem is in Normal.dot, and likely at a very deep
> level.
>
> In that case, I'd rename Normal.dot so that Word generates a clean
> copy. You could then use the Organizer to copy across toolbar, macros

> etc.
>
[quoted text clipped - 9 lines]
> This reply is posted in the Newsgroup; please post any follow question
> or reply in the newsgroup and not by e-mail :-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.