Results 1 to 8 of 8
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Commandbar customisation not working (2000)

    Hi everyone,

    I use this code in a global template to add a menuitem to the user's menu:

    Sub CreateCommandBar()
    On Error GoTo locerr
    Dim cCommandBar As CommandBar
    Dim cControl1 As Object
    Dim iCount As Integer
    Set cControl = Application.CommandBars("Menu Bar").Controls.Add(Type:= _
    msoControlPopup, Before:=Application.CommandBars("Menu Bar").Controls.Count + 1)
    cControl.Caption = "&Correspondence"

    With cControl.Controls.Add(Type:= _
    msoControlButton, Before:=1)
    .OnAction = "OpenHelp"
    .Caption = "&Help"
    .TooltipText = "Open Help file."
    .Enabled = True
    End With
    If bDatabase Then
    With cControl.Controls.Add(Type:= _
    msoControlButton, Before:=1)
    .OnAction = "SearchDatabase"
    .Caption = "&FindDoc"
    .TooltipText = "Search for documents in the database."
    .Enabled = bNetwork
    End With
    With cControl.Controls.Add(Type:= _
    msoControlButton, Before:=1)
    .OnAction = "WrapUp"
    .Caption = "F&inalise"
    .TooltipText = "Document ready, place a readonly copy on the network and update database."
    .Enabled = bNetwork
    End With
    End If
    With cControl.Controls.Add(Type:= _
    msoControlButton, Before:=1)
    .OnAction = "UpdateDocumentData"
    .Caption = "&UpDate"
    .TooltipText = "Update the database with current document data."
    End With
    If bUseNetwork Then
    With cControl.Controls.Add(Type:= _
    msoControlButton, Before:=1)
    .OnAction = "RequestDocNumber"
    .Caption = "&DocNumber"
    .TooltipText = "Request a document number."
    .Enabled = bNetwork
    End With
    End If

    With cControl.Controls.Add(Type:= _
    msoControlButton, Before:=1)
    .OnAction = "Main"
    .Caption = "&New Document"
    .TooltipText = "Letter, Fax en Memo Templates"
    End With

    ThisDocument.Saved = True
    TidyUp:
    Exit Sub
    locerr:
    If ReportError(Err.Description, Err.Number, "MainMod", "CreateCommandBar") = vbRetry Then
    Resume
    Else
    Resume TidyUp
    End If
    End Sub

    The sub is called from the AutoExec sub, which should fire (I guess) on the opening of the template, which resides in the users Startup folder.

    On some Wd2000/Win2000 systems however, the template does load, but the menuitem does NOT show up.

    What gives?

    Regards,

    Jan Karel Pieterse
    Excel MVP
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Commandbar customisation not working (2000)

    This code runs fine from an open module in the VBE (if I chop out the error checking section). Here are some thoughts on the AutoExec issue:
    1. <LI>AutoExec macros will run when Word starts if they are in either the Normal.dot template or in a global add-in. I think you're covered for templates that load from the Startup folder.
      <LI>These functions should work even before the blank document is created, assuming that the "CustomizationContext" is the Normal template. This can be set expressly to avoid confusion.
      <LI>Users can defeat Auto macros by holding the Shift key, but this is unlikely.
      <LI>If Macro Security is High and "Trust all installed add-ins and templates" is not checked, the template-based AutoExec probably will not run.
    That's all that comes to mind.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Commandbar customisation not working (2000)

    Thanks for your thoughts.

    - Macro security couldn't be high, since they have to set it to medium to be able to install it in the first place. But I'll check.

    - Will look into the Customizationcontext thing. Will that not cause the menu to appear in duplicate after closing and reopening? (I do run a "removemenu" sub before I add the menu though)
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Commandbar customisation not working (2000)

    Jan,

    I think it would be better to set the customization context to the global template, rather than Normal.dot.

    The following is untested, but perhaps worth trying:
    Put this statement somewhere at the beginning of your procedure in the global template:

    CustomizationContext = ThisDocument

    And put this toward the end:

    ThisDocument.Saved = True

    This should localize the command bar customization to the global template, and also ensure that users don't get a prompt to save the template when they quit Word.

    Gary

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Commandbar customisation not working (2000)

    Hi Gary,

    Thanks, I'll look into this.

    I assume the reason behind this is also to avoid the user seeing his Normal.dot changing everytime this commandbar change is done?
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Commandbar customisation not working (2000)

    Hi Gary, Jeff,

    Problem seems solved. Thanks for your assistance.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  7. #7
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Commandbar customisation not working (2000)

    Hi Jan,

    <<I assume the reason behind this is also to avoid the user seeing his Normal.dot changing everytime this commandbar change is done?>>

    You can prevent the user from getting a prompt that Normal.dot has been changed, by using "NormalTemplate.Saved = True", but generally it seems better policy to leave users' Normal.dots alone as much as possible.

    Also, it seems more reliable to localize the customization to the same global template the code is running in; for one thing, you can't totally anticipate or control the condition the user's Normal.dot will be in when you run the commandbar customization code, but you can anticipate/control the condition of the global template (assuming you make it read-only or make the startup directory read-only).

    Gary

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Commandbar customisation not working (2000)

    OK, I get the picture. Thanks.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

Posting Permissions

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