Consulting

Page 5 of 6 FirstFirst ... 3 4 5 6 LastLast
Results 81 to 100 of 117

Thread: Challenge!! Can you solve this problem?

  1. #81
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I agree, I think the scope is the answer, as in Commandbars would refer to the ActiveDocument (here and now) where Application.Commandbars would refer to Normal or everything instead of what is currently active (scope).

    I have not had a chance to check this.

  2. #82
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by Howard Kaikow
    It's my fault for not being clearer.

    In a real app, one might have something like the following.

    I distribute a template that installs an app on a user's system.
    The installation code allows the user to set up toolbar in various ways, e.g., to choose whether to locate the toolbar in Normal or another template.
    An option might be presented that causes no change to an extant toolbar.

    So, in most general case, one cannot do the deed in document_open.
    Sorry for not being as clear as I could have been.
    [VBA]
    Option Explicit
    Public Sub DeleteToolbars()
    Dim intBeforeIndex As Integer
    Dim cmdbar As CommandBar
    Dim cmdbutton As CommandBarButton
    Const strToolbar As String = "Double Vision HK VBA"
    CustomizationContext = MacroContainer
    CustomizationContext = NormalTemplate

    '//NOTE VERY CAREFULLY: IF you change/paste this code & run this macro before
    '//quitting you will have TWO toolbars on re-opening the doc. Running the macro
    '//again on re-open deletes the duplicate and youll NEVER have this problem again
    '//unless you tinker with the code & run it before quitting (a new user is not going
    '//to do that if the code is locked). IF you DONT run the code before quitting
    '//the two toolbars NEVER appear & the whole issue is totally redundent - WHY
    '//IS THIS SO? Who really cares? - It's an issue imposed on Word users by MS so
    '//we just have to accept, adapt, and think of ways to deal with the issue...E.G.

    '<< THIS (deletes all strToolbars) >>
    On Error Resume Next
    For Each cmdbar In CommandBars
    CommandBars(strToolbar).Delete
    Next cmdbar

    '<< INSTEAD OF THIS >>
    'On Error Resume Next
    'CommandBars(strToolbar).Delete
    'If Err.Number = 0 Then
    'Debug.Print "Toolbar deleted"
    'Else
    'Debug.Print "Toolbar NOT deleted"
    'End If
    'On Error GoTo 0

    'On Error Resume Next
    'CommandBars(strToolbar).Delete
    'On Error GoTo 0

    '//<< NOW LET'S MAKE A (strToolbar) >>
    Set cmdbar = CommandBars.Add(Name:=strToolbar, Position:=msoBarTop, tempORary:=False, MenuBar:=False)
    cmdbar.Visible = True
    Set cmdbar = CommandBars(strToolbar)

    intBeforeIndex = 1
    Set cmdbutton = cmdbar.Controls.Add(Type:=msoControlButton, tempORary:=False, Before:=intBeforeIndex)
    With cmdbutton
    .Style = msoButtonCaption
    ' Use whatever you need in next line to avoid compile errors.
    .OnAction = "modReplaceStringNames.ReplaceStringNames"
    .Caption = "String Names"
    End With

    End Sub
    [/VBA]

  3. #83
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by Tommy
    I agree, I think the scope is the answer, as in Commandbars would refer to the ActiveDocument (here and now) where Application.Commandbars would refer to Normal or everything instead of what is currently active (scope).

    I have not had a chance to check this.
    CommandBars would refer to whatever is the current CustomizationContext.

    Application.CommandBars should do the same, unless MSFT coded this to reset the context.

  4. #84
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Don't you people ever sleep (either)??
    ~Anne Troy

  5. #85
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by Dreamboat
    Don't you people ever sleep (either)??
    (and) (and) :rofl :rofl :rofl :rofl :rofl

  6. #86
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    It was suggested in another posting in this thread that it is possible to delete all occurrences of the toolbar prior to rebuilding the toolbar. I investigated this several years ago, alas, it is not true.

    Thus far, it seems that attempting to write the "Double Vision" toolbar in the Normal template always, eventually, causes both the multiple toolbar problem AND the travelling toolbar problem.

    TestingHowardKaikowDoubleVision.zip now contains:

    AttemptsToForcesDeleteTestingHowardKaikowDoubleVision.dot
    DoesNotForceDeleteTestingHowardKaikowDoubleVision.dot

    Clearly, there is at least a problem adding toolbars to the Normal template.

    In order to wind down this thread, I suggest the following.

    I will run both templates unchanged, using both MacroContainer and NormalTemplate, in Word 97, Word 2000, Word 2002, and Word 2003.

    I am hoping to satisfy myself that there is not a problem using MacroContainer, and that there is a problem using NormalTemplate, and in which Word versions.

    It would be useful if at least, say, 3 others ran the same tests with unchanged code, for each version of Word. And posted their findings here.

    P.S. I pulled out the hard coded "Test toolbar" and added code (not tested very well) to dynamically add the toolbar. This might help eliminate the 5852 error somebody encountered.

  7. #87
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by Howard Kaikow
    It was suggested in another posting in this thread that it is possible to delete all occurrences of the toolbar prior to rebuilding the toolbar. I investigated this several years ago, alas, it is not true.

    Thus far, it seems that attempting to write the "Double Vision" toolbar in the Normal template always, eventually, causes both the multiple toolbar problem AND the travelling toolbar problem.

    TestingHowardKaikowDoubleVision.zip now contains:

    AttemptsToForcesDeleteTestingHowardKaikowDoubleVision.dot
    DoesNotForceDeleteTestingHowardKaikowDoubleVision.dot

    Clearly, there is at least a problem adding toolbars to the Normal template.

    In order to wind down this thread, I suggest the following.

    I will run both templates unchanged, using both MacroContainer and NormalTemplate, in Word 97, Word 2000, Word 2002, and Word 2003.

    I am hoping to satisfy myself that there is not a problem using MacroContainer, and that there is a problem using NormalTemplate, and in which Word versions.

    It would be useful if at least, say, 3 others ran the same tests with unchanged code, for each version of Word. And posted their findings here.

    P.S. I pulled out the hard coded "Test toolbar" and added code (not tested very well) to dynamically add the toolbar. This might help eliminate the 5852 error somebody encountered.
    1) You say you have investigated this.....But have you actually TRIED what I have posted above? I have tried it many many times and can either get it to run flawlessly every single time, or, by tinkering with the code as I've commented, can get a duplicate every single time.

    2) I have also used microsofts own code (from their help files) and if you put the exact same process in microsofts code (delete a toolbar and add a toolbar but with Temporary=False) the exact same thing happens...Two toolbars will appear if the code is tinkered with before Quitting - THE ACTUAL CODE USED IS TOTALLY AND COMPLETELY IRRELEVANT, IT'S THE PROCESS (delete a toolbar and add a toolbar with Temporary=False) THAT IS FLAWED AND CAUSING THE PROBLEM,...So,

    3) As the actual code used is irrelevant, to simplify things, can we please stick with the original code and forget these extra examples?

  8. #88
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    The only way to reach a conclusion is for everybody to run the same code, and to comment on that code.

    The revised version I posted is a much better candidate because it most clearly isolates a means to identify what is the likely problem area, not to mention that providing the toolbar "Test toolbar" makes it a lot easier to run the tests.

  9. #89
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by Howard Kaikow
    It was suggested in another posting in this thread that it is possible to delete all occurrences of the toolbar prior to rebuilding the toolbar. I investigated this several years ago, alas, it is not true.

    Thus far, it seems that attempting to write the "Double Vision" toolbar in the Normal template always, eventually, causes both the multiple toolbar problem AND the travelling toolbar problem.

    TestingHowardKaikowDoubleVision.zip now contains:

    AttemptsToForcesDeleteTestingHowardKaikowDoubleVision.dot
    DoesNotForceDeleteTestingHowardKaikowDoubleVision.dot

    Clearly, there is at least a problem adding toolbars to the Normal template.

    In order to wind down this thread, I suggest the following.

    I will run both templates unchanged, using both MacroContainer and NormalTemplate, in Word 97, Word 2000, Word 2002, and Word 2003.

    I am hoping to satisfy myself that there is not a problem using MacroContainer, and that there is a problem using NormalTemplate, and in which Word versions.

    It would be useful if at least, say, 3 others ran the same tests with unchanged code, for each version of Word. And posted their findings here.

    P.S. I pulled out the hard coded "Test toolbar" and added code (not tested very well) to dynamically add the toolbar. This might help eliminate the 5852 error somebody encountered.
    I have just finished downloading Johnske's latest code and I ran the code.

    That code ALSO has the problem when the toolbar is written to the NormalTemplate. The easiest way to see this is to run the code writing to the Normal template, say 3 times, exiting from Word after each time. Exit from Word then start Word with the Normal template. You will see more than one toolbar and repeated executions will show the toolbar travelling.

    We need to all be looking at the same code, and I will be looking at my latest posting as it more clearly isolates the problem and provides a toolbar to assist in running the tests.

  10. #90
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    ????? I've also tried it in the Normal template - as I said, it runs flawlessly ?????

  11. #91
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by Howard Kaikow
    I have just finished downloading Johnske's latest code and I ran the code.

    That code ALSO has the problem when the toolbar is written to the NormalTemplate. The easiest way to see this is to run the code writing to the Normal template, say 3 times, exiting from Word after each time. Exit from Word then start Word with the Normal template. You will see more than one toolbar and repeated executions will show the toolbar travelling.

    We need to all be looking at the same code, and I will be looking at my latest posting as it more clearly isolates the problem and provides a toolbar to assist in running the tests.
    OH, by the way, when you say "writing to the Normal template, say 3 times..." I most certainly hope you dont mean writing code, running it then quitting do you?...

    Because I can also get it to do EXACTLY the same thing that you just described (i.e. multiple toolbars and all moving to the right) if I do that too - in which case you have not read what I have written in the comments in the code and also in several of my previous posts. - It is by far THE most important part of all so I will repeat it once more...IF YOU WRITE VB CODE IN THE MODULE, YOU MUST NOT RUN THE CODE UNTIL AFTER YOU SAVE/QUIT AND RE-OPEN THE DOC!!.

  12. #92
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by Dreamboat
    I will shortly be posting a new link for this problem.

    It will give explicit instructions on how to reproduce the problem.

  13. #93
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Howard, I'm listening in still. Please let me know when/if you'd like me to test in any version (97 through 03) on my WinXP.
    ~Anne Troy

  14. #94
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by Howard Kaikow
    I will shortly be posting a new link for this problem.

    It will give explicit instructions on how to reproduce the problem.
    Done.

    I think the bookmarks will still work.

    I've restructured the entire link and added explicit instructions.

    I likely should have been more explicit earlier.

  15. #95
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by Dreamboat
    Howard, I'm listening in still. Please let me know when/if you'd like me to test in any version (97 through 03) on my WinXP.
    Great!

    You can let us know whether my explicit instructions were explicit enough.

  16. #96
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    In order to reduce the chance of version incompatibilities, I rebuilt the templates using Word 97 and put the .zip file at http://www.standards.com/OhMyWord/VB...teToolbar.html.

    I had to change AutoExit to AutoClose to make Word 97 happy.

    I ran only the test that writes the toolbar in the Normal template and attempts to force deletion of all instances of the toolbar.

    All worked correctly in Word 97.
    In Word 2000, Word 2002, and Word 2003 all had the expected error, and at the expected time, i.e., after running only two iterations of the instructions in
    http://www.standards.com/OhMyWord/VB...teToolbar.html.

    There were some significant changes made to the CommandBar object for Word 2000. It could be that this resulted in a (mis)design change. Of course, this may make no sense, but unless we learn the secret, we may be stuck with duplicate toolbars in such apps.

    Oh well, it's not a good idea to put unnecessary stuff in the Normal template.
    Guess I'll move my toolbars out of Normal and see if that breaks anything.

  17. #97
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I'll verify that the error still happens in Word 2000 SP3.

    I am also still getting the 5850 error. It only happens with the downloaded versions, no other docs on "my" machine have this error. The error is thrown when I exit word.

    I will test again with Word 2000 with no SP's later tonight.

    Later

  18. #98
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by Tommy
    I'll verify that the error still happens in Word 2000 SP3.

    I am also still getting the 5850 error. It only happens with the downloaded versions, no other docs on "my" machine have this error. The error is thrown when I exit word.

    I will test again with Word 2000 with no SP's later tonight.

    Later
    If it is happening on exit, that's a sure sign of interference from some 3rd party macro or app.

    The latest download was created fresh in Word 97 from a virgin template file, i.e., no extraneous project references.

  19. #99
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by Tommy
    I'll verify that the error still happens in Word 2000 SP3.

    I am also still getting the 5850 error. It only happens with the downloaded versions, no other docs on "my" machine have this error. The error is thrown when I exit word.

    I will test again with Word 2000 with no SP's later tonight.

    Later
    There's no point in testing with other than the latest SP/SR of each Word version.

    This duplicate toolbar problem appears to have been caused by some design change made in Word 2000 that persists thru Word 2002 and Word 2003.

    Indeed, the example I posted is very simple code. The only "complex" part is the passing of the template as an arg into the UseCustomizationContext sub. The code itself makes no distinction between MacroContainer and NormalTemplate.

    Whatever is causing the duplicate toolbars is triggering something on your system to cause the error 5852.

    My recollection is that you first encountered the error 5852 prior to my adding the "Test Toolbar". I just posted another .zip that removes the AutoClose, as it was not needed. You also could outright remove the "Test Toolbar" and run the code in the usual way.

    Unexplained errors, such as the error 5852 you see, are usually the result of nasty interaction with add-ins such as PDFMaker, or whatever. They do not show up for all templates.

    I ran into a similar problem with PDFMaker a few years ago, see http://www.standards.com/OhMyWord/VB...ordMacros.html.

  20. #100
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by Tommy
    I'll verify that the error still happens in Word 2000 SP3.

    I am also still getting the 5850 error. It only happens with the downloaded versions, no other docs on "my" machine have this error. The error is thrown when I exit word.

    I will test again with Word 2000 with no SP's later tonight.

    Later
    One thing to try.

    1. Double-click on the template that appears to result in the 5852 error.
    2. Immediately exit from Word. Does an error occur here?
    3. If an error did occur in step 2:
    a. Again, double click on the template.
    b. Immediatelty, create a blank document based on the Normal template.
    c. Do not exit Word, but close the document not based on the Normal template. Was there an error here?
    d. Exit from Word, was there an error here.
    4. If an error did not occur in step 2:
    a. Again, double click the template.
    b. Run one of the macros.
    c. Immediately exit from Word. Does an error occur here?
    d. If an error did occur:
    e. Again, double click on the template.
    f. Run one of the macros.
    g. Immediately, create a blank document based on the Normal template.
    h. Do not exit Word, but close the document not based on the Normal template. Was there an error here?
    i. Exit from Word, was there an error here?

    I hope the above is semi-clear.
    The idea is to separate the closing of the template from the exiting from Word.

    Wow! This was posting 100 in this thread!!

Posting Permissions

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