Consulting

Results 1 to 14 of 14

Thread: How to disable Word 2003 Toolbars in Word 2007/2010/2013

  1. #1

    How to disable Word 2003 Toolbars in Word 2007/2010/2013

    I have a number of Word 2003 templates containing various toolbars. Some friends using 2010 would like to use these templates, but the associated toolbars look very messy as addins on the ribbon, especially since all the toolbars get displayed simultaneously on the Custom toolbars ribbon tab, with large parts of them off the RH end of the ribbon, which is both confusing and messy for users. Is it possible to write VBA code that will selectively remove or add the toolbars (but not the templates that house them) from the ribbon? Or is it a matter of having all the toolbars or none at all? I don't have access to Word 2007, so it is difficult to tinker and to see what is possible.

    I suppose that I could put the toolbars into separate Word 2003 templates and have code to disable the templates programmatically, through "Templates Organizer", but I'd rather not spend time on that if there is a way of disabling specific custom toolbars in Word 2007 / 2010 etc. I do do that for a selection of additional menus in the main menu, which enables me to toggle menu commands on and off at the click of a button.

    Thanks

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    You would need to take the code out to create the menu first of all. Then you could need to write the XML to create the ribbon as well as the callbacks. You can tie them together fairly easily, and as long as you know what the control images should look like, named, etc, it's fairly easy to do.

    Do you know what kind of controls you would want on the ribbon? There are plenty of examples on this site, and if you're planning on doing this yourself, I'd start with these links for learning the ribbon...

    http://msdn.microsoft.com/en-us/libr...ffice.12).aspx (Part 1)
    http://msdn.microsoft.com/en-us/libr...ffice.12).aspx (Part 2)
    http://msdn.microsoft.com/en-us/libr...ffice.12).aspx (Part 3)

    These links were based on Office 2007, but will still work in subsequent versions. There are some minor differences in 2010/2013, like the backstage view compared to the office menu. For loading different ribbon customizations take a look at Ron de Bruin's page on it...

    http://rondebruin.nl/win/s2/win002.htm

    Please post back if we can help you further.

  3. #3
    Oops!
    Last edited by johndavidson; 02-08-2014 at 09:14 PM.

  4. #4
    Thanks. In the end, I did put the Word 2003 toolbars into separate templates, and wrote the code to toggle the installation/uninstallation of the templates, setting a regkey true/false for each of the toolbars. Then I put an AutoExec into one of the templates (John.dot) to check the reg status at startup and install/uninstall the toolbar templates accordingly. This works OK on my 2003 system (I don't have Word 2010), but a friend who tested it on their computer (with both 2003 and 2010) is having issues with the template (John.dot) that contains the AutoExec not getting installed at startup. It has to be installed manually after startup. So we still have some issues. It's probably something in the AutoExec because if I put an Exit Sub at the start of the AutoExec, then the template is installed correctly (but without checking the status of the toolbar regkeys). Maybe the regkeys need to be pre-created for the first time Word is opened with the new templates in the Startup folder.

    Your solution is more elegant, but I don't have the time (or Word 2010) to get into programming the ribbon at the moment. Something for the future, and when I have Word 2010 (coming soon).

    For your interest and anyone else's, here's the code I am using (noting that there are still issues - I think - with the AutoExec code). If anyone can see what the problem is, I'd be delighted to know!

    [vba]Sub AutoExec()
    Application.CommandBars("Web").Enabled = False
    Call AutoExec_Do("Toolbars")
    Call AutoExec_Do("MenusToolbar")
    Call AutoExec_Do("TextFixerToolbar")
    Call AutoExec_Do("QuoteFinderFindFileToolbars")
    End Sub


    Sub AutoExec_Do(template As String)

    Dim jTemplate As String
    Dim WordStartUpPath As String
    Dim menuStatus As String
    Dim regKey As String


    WordStartUpPath = Options.DefaultFilePath(wdStartupPath)
    jTemplate = WordStartUpPath & "\" & template & ".dot"

    regKey = template & "Status"


    If FileOrDirExists(jTemplate) = False Then
    MsgBox "Toolbar: " & template & ".dot is not in Word's Startup folder", vbOKOnly, "Toggle Toolbars"
    Exit Sub ' In case someone has removed the template from the StartUp Folder
    End If


    menuStatus = GetSetting("Toolbars", regKey, "Save" & regKey, "")

    ' If reg key is absent (menuStatus = ""), it means that the user has not yet toggled the toolbar in the Toolbars toolbar menu
    ' If this is Word 2007 (Version 12) onwards then leave the menu toolbar uninstalled
    If menuStatus = "" And Application.Version > 11 Then
    AddIns(jTemplate).Installed = False
    SaveSetting "Toolbars", regKey, "Save" & regKey, "False"
    Exit Sub
    End If


    If menuStatus = "False" Then
    AddIns(jTemplate).Installed = False
    SaveSetting "Toolbars", regKey, "Save" & regKey, "False"
    End If


    End Sub[/vba]

    And here’s the Toolbars toolbar code that toggles the template installations on and off:

    [vba]Sub MenusToolbarToggle()
    ' Shift/Alt/M
    Call ToolbarToggle_Do("MenusToolbar")
    End Sub


    Sub ToolbarsToggle()
    Call ToolbarToggle_Do("Toolbars")
    End Sub


    Sub QuoteFinderFindFileToolbarsToggle()
    Call ToolbarToggle_Do("QuoteFinderFindFileToolbars")
    End Sub


    Sub TextFixerToolbarToggle()
    Call ToolbarToggle_Do("TextFixerToolbar")
    End Sub


    Sub ToolbarToggle_Do(template As String)

    ' Check & set status of HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Toolbars\(template) & "Status"

    Dim jTemplate As String
    Dim WordStartUpPath As String
    Dim menuStatus As String
    Dim regKey As String
    Dim dummy As Boolean


    If Documents.Count < 1 Then
    MsgBox "To run this command, there must be at least one open document.", vbOKOnly, "Toggle Toolbars"
    Exit Sub
    End If


    regKey = template & "Status"

    WordStartUpPath = Options.DefaultFilePath(wdStartupPath)
    jTemplate = WordStartUpPath & "\" & template & ".dot"


    If FileOrDirExists(jTemplate) = False Then
    MsgBox "Toolbar: " & template & ".dot is not in Word's Startup folder", vbOKOnly, "Toggle Toolbars"
    Exit Sub ' In case someone has removed the template from the StartUp Folder
    End If


    menuStatus = GetSetting("Toolbars", regKey, "Save" & regKey, "")
    If menuStatus = "False" Then
    AddIns(jTemplate).Installed = True
    SaveSetting "Toolbars", regKey, "Save" & regKey, "True"
    Else
    AddIns(jTemplate).Installed = False
    SaveSetting "Toolbars", regKey, "Save" & regKey, "False"
    End If


    ' Make it happen on the current Active Document
    ' There is probably something else we could do to ensure that the changes get implemented right away on the Active Document
    ' But this is what the VBA recorder uses when the user exits Tools > TemplateOrganizer
    ' Opening another document or switching to another document does the same thing
    dummy = ActiveDocument.XMLSchemaReferences.AutomaticValidation
    ActiveDocument.XMLSchemaReferences.AutomaticValidation = dummy ' Validate (or not) the XML in a document as a user types


    End Sub[/vba]
    Last edited by Zack Barresse; 02-08-2014 at 09:15 PM. Reason: Added VBA tags

  5. #5
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Sorry, I didn't realize this was an add-in which needed to work in 2003-2013. Is this in the new file format, or in DOC format? Customizing the ribbon will need to be done in the new file format. There's a way to do it in previous file format but it's not as easy. Some people just opt for two versions, one in the old file format, and a completely new add-in optimized for the ribbon for 2007 and on add-ins. What are you using exactly?

    As far as writing to the registry, I'm not opposed to it, but a new install would write new settings to the registry as well, regardless of application version. So I'm not sure that's the best approach. I think a simple Application.Version check in the Open event of the file should do it. But again, it depends on the file type you're using.

  6. #6
    Thanks. The templates are all 2003 *.dot format. I'm using 2003 for a large writing project, and some of the others who are helping are using 2007 +. I'm not a VBA expert and my software efforts are only an aid to what we are doing; so as long as it works for everyone who wants to use it, that's good enough. The registry settings get set by both 2003 and 2007 +, and if someone is running a dual system, the same settings presently apply to both versions of Word.

    I thought of using a text file to hold the data, in fact I coded for that originally, but the regkey seemed a simpler solution, esp. since regkeys are commonly used in other parts of the software with the project anyway (much of it written by more advanced programmers than I).

    The Autoexec code is being run from a *.dot template. In fact, all the templates are *.dot (Office 11).

    Rgds

    John Davidson

  7. #7
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    To get a file working in all versions you'd need two separate files. Ron de Bruin shows how to do this with Excel files here:

    http://www.rondebruin.nl/win/s2/win017.htm

    The basic logic is if you open the file in 2003 or prior, it creates the menu in code on the command bar. If the version is 2007 or later it opens the add-in which contains the custom ribbon code and does not create the command bar menu(s).

    So if you wanted both, you could do that. One important item (of Ron's solution) is to use the Activate/Deactivate events of the file. You can only do this with a class module in Word. Here is an example...

    Create a class module named "clsApp" (you can name it whatever you want, just make sure to change the reference in the code) and past this code:
    [vba]Option Explicit

    Public WithEvents wdApp As Word.Application

    Private Sub wdApp_WindowActivate(ByVal Doc As Document, ByVal Wn As Window)
    If Doc.Name = ThisDocument.Name Then
    'create menu
    End If
    End Sub

    Private Sub wdApp_WindowDeactivate(ByVal Doc As Document, ByVal Wn As Window)
    If Doc.Name = ThisDocument.Name Then
    'delete menu
    End If
    End Sub[/vba]
    In your ThisDocument module, add this line above all routines (but below any 'Option' statement):
    [vba]Dim oApp As New clsApp[/vba]
    In your AutoExec() routine add this line:
    [vba]Set oApp.wdApp = Word.Application[/vba]
    Now when your AutoExec runs you'll have Activate/Deactivate events for that workbook, which you can use to create/destroy any menus. Since a customized ribbon is per file, it only displays while the file is open, so this is needed to simulate that effort.

    Does this help?

  8. #8
    Thanks again. I'm getting a little out of my depth here, but if I understand correctly you're suggesting that the template autoexec checks the Word version and either goes with the menus / toolbars (in 2003) or programmatically creates a customized ribbon (if 2007 +). That is certainly a better solution for the future, but it's going to require some time, which I don't presently have. Also, the 2003 system is where all the development gets done as needs arise within the main non-software project where the macros are getting used, so toolbars change quite frequently ...

    But I am so near to a more cludgy solution using the installation/uninstallation of templates technique that I think I'll persevere with that for the moment. Presently, there's something in the autoexec that is causing that template not to be installed (for some users) while another user reports the VBA error message "Compile error in hidden module: NewMacros. This error commonly occurs when code is incompatible with the version, platform, or architecture of this application. Click "Help" for information on how to correct this error." There are solutions on the internet, so I'll work through those.

  9. #9
    Having gone a little further, and resolved all other issues, I am left with the problem that Word 2010 simply does not display all the toolbars in the installed templates in the custom toolbars space of the Addins tab. This of course makes it impossible to use! Does anyone have any ideas how to fix this? It sounds very much like the perennial problems/bugs with toolbars and menu items in Word 2003. If I move the toolbars around and put them into separate templates etc, it changes the selection of toolbars that appear in the Addins tab. For much of this testing period, I have only had 2 out of 20 toolbars displayed. Having moved them around, I can now see only one small toolbar!!

    Before I started this little project, many - but not all - of the 20 toolbars appeared in the Addins tab. Moving them around (using Templates Organizer in Word 2003) has made matters progressively worse.

    Any insights or solutions would be most welcome.

    Thanks

  10. #10

    Selectively display Word 2003 Toolbars in the Addins Custom Toolbar area in Word 2010

    My thoughts concerning the buggy nature of MS-Word's toolbar feature were (in this instance) unfounded. The solution, as I found online at http://www.thedoctools.com/index.php...r_missing_2007, is to explicitly display/hide the toolbars using standard VBA code:

    E.g. CommandBars("MyToolbar").Visible = True / False

    So I've worked this into a userform that displays all the custom toolbars in a listbox for user selection, and we now have complete control of what appears and does not appear in both the Menu Commands area as well as the Custom Toolbars areas of the Addins tab. The resulting template is attached in case it is of use to anyone. It has a few items that are specific to our set up, such as saving the displayed toolbar status in the registry, but it can be be modified as required.

    Programming the ribbon would no doubt be a more elegant solution - but for another day.

    Thanks for your help.
    Attached Files Attached Files

  11. #11
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Sorry I haven't responded to your last couple of posts, been busy over here. Glad you got a working solution though. Post back if you need anything done with the ribbon.

  12. #12
    Here's an update to the previous AutoToolbars template that enables a user to select which Custom Toolbars they wish to have visible.
    Attached Files Attached Files

  13. #13
    VBAX Regular
    Joined
    Jul 2014
    Posts
    14
    Location
    Thank you for your help

  14. #14

    AutoToolbars Update

    Here's the latest version, attached. It handles Word 2013 better, although in all versions of Word 2007 onwards, there is still an issue over the M+ Toggle Menus Toolbar, which toggles the Menus toolbar extensions on/off. It doesn't always do as asked until Word is restarted, despite using such things as DoEvents. Works fine in Word 2003.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •