Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: AutoExec: reating a CommandBar at startup (English, Word 2003, SP 2)

    This is just a guess, but I have seen similar errors caused by attempting to use ActiveDocument when word doesn't have any documents open. Can you add a check for Application.Documents.Count being greater than 0 into your code, and simply exit if it is 0?

    The other thing to check when manipulating CommandBars is that Application.CustomizationContext points to a valid document. Are you setting this in your code?

    StuartR

  2. #2
    New Lounger
    Join Date
    Jan 2002
    Location
    Champaign, IL, USA, Illinois, USA
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    AutoExec: reating a CommandBar at startup (English, Word 2003, SP 2)

    (Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>)

    I have created a template in the StartUp folder containing a Class Module and the Regular Module that goes with it as described in

  3. #3
    New Lounger
    Join Date
    Jan 2002
    Location
    Champaign, IL, USA, Illinois, USA
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: AutoExec: reating a CommandBar at startup (English, Word 2003, SP 2)

    I have checked the CommandBar, and it is correctly customized to store in the same Template as the code.

    I suspected what you are saying you observed, that Word is an unhappy camper if a document is not loaded when running or exiting the CommandBar program. If that is so, then the question becomes how to get around the problem, if there is a way. I actually tried delaying the Call to the CommandBar procedure for up to 30 seconds (Application.OnTime = Now + TimeValue ("00:00:30"), but still got the error message, just 30 seconds later after the standard blank

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: AutoExec: reating a CommandBar at startup (English, Word 2003, SP 2)

    > I have checked the CommandBar, and it is correctly customized to store in the same Template as the code.

    Can you show us the actual line of code that sets the vaule of Application.CustomizationContext

    regards,

    StuartR

  5. #5
    New Lounger
    Join Date
    Jan 2002
    Location
    Champaign, IL, USA, Illinois, USA
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: AutoExec: reating a CommandBar at startup (English, Word 2003, SP 2)

    The following code is in the procedure that creates the CommandBar. The Template holding all the code is called "StartUpTester.dot"

    '* CustomizationContext values defined
    Dim objOldContext As Object
    Dim strTemplateHoldingMenu As String

    '* Load CustomizationContext values
    Set objOldContext = Application.CustomizationContext
    strTemplateHoldingMenu = "StartUpTester.dot"

    Application.CustomizationContext = Documents(strTemplateHoldingMenu)

    ***********
    After posting the above code, I checked it out by commenting out each line and then activating the code line by line. The error message occurs for Application.CustomizationContext = Documents(strTemplateHoldingMenu).

    I also found another, related problem in the code that returns the Customization Context to the previous value (NormalTemplate). I got an error message "Bad file name" for the line Documents(strTemplateHoldingMenu).Saved = True

    Application.CustomizationContext = objOldContext
    Documents(strTemplateHoldingMenu).Saved = True

    Thanks for help isolating where the error message triggers. Unfortunately, even knowing something is wrong with the line of code, I can't see anything wrong with it, so I still don't know what to do to fix the problem.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: AutoExec: reating a CommandBar at startup (English, Word 2003, SP 2)

    A global template is not part of the Documents collection (unless it has been opened as a document), so Documents(strTemplateHoldingMenu) is not valid. You can refer to the document or template that contains the code being executed as MacroContainer, so try

    Application.CustomizationContext = MacroContainer

  7. #7
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: AutoExec: reating a CommandBar at startup (English, Word 2003, SP 2)

    If this code only runs during application startup, then you can reset the CustomizationContext to its default value using

    <code>application.CustomizationContext = NormalTemplate</code>


    StuartR

    Edited to add...

    If you want to set the saved property of your template to true, then you should use the Templates collection, rather than the documents collection. Try

    <code>Templates(strTemplateHoldingMenu).Saved = True</code>
    or using Hans' idea
    <code>MacroContainer.Saved = True</code>


    SR

  8. #8
    New Lounger
    Join Date
    Jan 2002
    Location
    Champaign, IL, USA, Illinois, USA
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: AutoExec: reating a CommandBar at startup (English, Word 2003, SP 2)

    I tried the suggestions of the two previous posts. Unfortunately the line Application.CustomizationContext = MacroContainer triggers the same error code as before.

    Both
    Application.CustomizationContext = Application.Templates(strTemplateHoldingMenu)
    and
    Application.CustomizationContext = Application.Templates(

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: AutoExec: reating a CommandBar at startup (English, Word 2003, SP 2)

    Since you get the error "The referenced member of the collection does not exist", try including the following code in your AutoExec:

    Dim i As Integer
    For i = 1 To Application.Templates.Count
    MsgBox i & ": " & Application.Templates(i).Name
    Next i

  10. #10
    New Lounger
    Join Date
    Jan 2002
    Location
    Champaign, IL, USA, Illinois, USA
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: AutoExec: reating a CommandBar at startup (English, Word 2003, SP 2)

    As suggested, I checked for active templates both in both the AutoExec procedure and the called procedure that creates the CommandBar menu. In both cases, it shows StartUpTester.dot and Normal.dot as would be expected. So, Word VBA appears to recognize the template here, but has problems working with it as described in prevous posts.

    Strange.

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: AutoExec: reating a CommandBar at startup (English, Word 2003, SP 2)

    Try the following:

    Dim tpl As Template
    For Each tpl In Application.Templates
    If tpl.Name = "StartUpTester.dot" Then
    Application.CustomizationContext = tpl
    Exit For
    End If
    Next tpl

  12. #12
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: AutoExec: reating a CommandBar at startup (English, Word 2003, SP 2)

    Graeme
    Am I correct in assuming that the only file in your STARTUP folder is StartUpTester.dot?
    Regards
    Don

  13. #13
    New Lounger
    Join Date
    Jan 2002
    Location
    Champaign, IL, USA, Illinois, USA
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: AutoExec: reating a CommandBar at startup (English, Word 2003, SP 2)

    First, Hans, your code works. Thank you so much. I have no idea why that should be effective when putitng the name of the template into the code by copying it from the immediate window (?ActiveDocument.AttachedTemplate) does not.

    I am still having problems with closing the template without saving when Word closes. I cannot find how to name the template so I can the add "= saved" and have VBA accept it. Also, I have not quite figured out all of how word saves CommandBars. Even after running a program to delete the CommandBars, or deleting them from the Customizing option when right-clicking in the toolbar area, if I save the template. Pop, there they are at next opening. I would have thought that after deleting them the template would not keep a copy.

    Don, the only other template in the StartUp file is Word Code Cleaner.dot, which I downloaded (don't have the address right with me). I am really not using it, but it is sitting there.

    Thanks again for your continued help.

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: AutoExec: reating a CommandBar at startup (English, Word 2003, SP 2)

    You cannot use tpl = Saved. Instead, use tpl.Saved = True.

    I gather that you have code that creates the toolbar when the template is loaded. That would explain why it returns each time.

  15. #15
    New Lounger
    Join Date
    Jan 2002
    Location
    Champaign, IL, USA, Illinois, USA
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: AutoExec: reating a CommandBar at startup (English, Word 2003, SP 2)

    Sorry, my "= Saved" shorthand was too short.

    Each of the following four lines generated the

Page 1 of 2 12 LastLast

Posting Permissions

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