Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Part-Time Menus? (Word XP VBA)

    Hi, all.
    I have written a template (CAProtocol.dot) that contains commands that only need to be viewed by certain users. These users are easily identified at runtime because only they have another specific template (WPC.dot); currently, I check to see if the "current user" is using this template, and thus know if they are the "power users" in question.

    Currently, I use this process to temporarily add a menu option associated with code in CAProtocol to a toolbar in the WPC template. I also have a piece of code that removes it once all CAProtocol-based documents have been closed. Apologizing in advance for hogging the screen, here is the code for both creating (on Document_Open()) and removing the menu option:

    <font face="Georgia"> Private Sub Document_Open()
    WPCTemplateCommands
    End Sub

    Private Sub Document_Close()
    Dim CustomProtocolMenu As CommandBarControl
    Dim WPCAddIn As Document, cProtocol As Document
    Dim WPCTemplate As AddIn, WPCAddInPresent As Boolean

    Dim oTemplate As Template
    Dim oDocument As Document
    Dim OtherProtocolsOpen As Boolean

    'This error handler is inserted to prevent errors on some machines when the ForEach stumbles on a bogus entry in the AddIns collection.
    On Error Resume Next
    'First, check to see if the WPC template is installed. If not, then quit
    For Each WPCTemplate In AddIns
    If UCase(WPCTemplate.Name) = "WPC.DOT" Then WPCAddInPresent = True
    Next

    If WPCAddInPresent <> True Then GoTo Done
    If AddIns("WPC.dot").Installed = False Then GoTo Done

    Set cProtocol = ActiveDocument

    For Each oDocument In Documents
    Set oTemplate = oDocument.AttachedTemplate
    If oTemplate.Name = "CAProtocol.dot" And oDocument <> cProtocol Then
    OtherProtocolsOpen = True
    Exit For
    End If
    Next

    If OtherProtocolsOpen = True Then GoTo Done

    'Remove the RDS Protocol Utilities menu option if no other open docs use the Protocol Template =====================
    On Error GoTo Done

    Set CustomProtocolMenu = Application.CommandBars("RDS Utilities").Controls("RDS Protocol Utilities")
    Set WPCTemplate = AddIns("WPC.dot")
    Set WPCAddIn = Documents.Open(FileName:=WPCTemplate.Path & "" & WPCTemplate.Name, Visible:=False)

    CustomProtocolMenu.Delete

    WPCAddIn.Saved = True
    WPCAddIn.Close SaveChanges:=False

    Done:
    End Sub
    </font face=georgia>

    Now, a problem I'm sometimes seeing is that, for some reason, I'm still being prompted to save changes to the WPC template when I exit Word. This is a big problem since my company has an unattended process that opens documents based on the CAProtocol template and which halts if it's being prompted to save the template! Can anyone tell me if the way I try to avoid that (by opening the template and setting Saved=True) is the best way to do that? Alternatively, I've considered adding those menu options to the WPC template permanently and associating the commands with code in CAProtocol; while not elegant (I assume the commands will return an error if no open doucments are attached to CAProtocol), I'm leaning this way to avoid any possible user prompts about saving files.

    (BTW, I'm MORE than willing to listen to anyone's assessment of the code I've written so far, or any alternatives I haven't thought of!)
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  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: Part-Time Menus? (Word XP VBA)

    I can't see where you are creating the menu. I believe there is a "temporary" parameter for the Add method of the CommandBarControls collection (just as there is such a parameter for the Add method of the CommandBars collection). Does using it avoid marking the relevant "CustomizationContext" document or template as changed?

  3. #3
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Elkins Park, Pennsylvania, USA
    Posts
    325
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Part-Time Menus? (Word XP VBA)

    Sorry. The "WPCTemplateCommands" subroutine that's called at Document_Open creates that PopUp control. I'm attaching the code in a text-file.

    I just noticed that the PopUp control I add to the toolbar is set as Temporary, but the options under it are not. Might that be a problem?
    Attached Files Attached Files
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  4. #4
    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: Part-Time Menus? (Word XP VBA)

    I think it's worth testing with as much stuff "temporary" as possible. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> However, I am not able to test it for myself at the moment.

Posting Permissions

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