Consulting

Page 1 of 6 1 2 3 ... LastLast
Results 1 to 20 of 117

Thread: Challenge!! Can you solve this problem?

  1. #1
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location

    Challenge!! Can you solve this problem?

    ~Anne Troy

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    I tried with Word 2002 and could not duplicate the issue.

  3. #3
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Hi Anne,

    I couldn't duplicate the exact problem as described either, but I did get a duplicate once....See if this fixes it on yours (it appears it did on mine)

    John

    Edit: The problem appears to be that the single procedure was deleting the toolbar and then immediately adding the toolbar back in, and there was also a duplication of one piece of code. I deleted the duplication and split delete and add into two separate procedures (done on Office 2000 Premium edition)

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi,
    I couldn't replicate it either (Word 2000). I agree the delete and remake are too close together and this may cause the problem. Things don't always happen in "real life" as they do in stepping through a macro. I would allocate Delete Tooolbar to a DocumentOpen event in the template
    MD

  5. #5
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by mdmackillop
    Hi,
    .....I agree the delete and remake are too close together and this may cause the problem. Things don't always happen in "real life" as they do in stepping through a macro. I would allocate Delete Tooolbar to a DocumentOpen event in the template
    MD
    Yep, that's definitely it! I went back in and ran the delete/remake as a single procedure again, followed instructions, and ended up with THREE toolbars. It seems that there is simply not always enough TIME for the toolbar to be successfully deleted before the code creating a new one is activated.

    Even slowing it down by simply changing "debug.print" to "MsgBox" slows everything down enough for it to run correctly (without duplicated toolbars) - a simple pause or some other operation should also do the trick

  6. #6
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    I can replicate this (2000 w/o SP1 or SP2 at the moment).

    I am not comfortable with the explanation given though. It is perfectly reasonable (and not uncommon) to delete an object (for safety's sake) before (re-)creating it and I've never heard of this happening before.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  7. #7
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I think this is the problem.

    tempORary:=False

    When the tool bar is created it sets the temporary flag to false. I don't know this but Word may place the information (the toolbar) in a seperate area for permanent tollbars vs temp toolbars.

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Tony,
    I had a similar problem here.
    Solved: Find text in Excel workbook
    My code created added a worksheet and then tried to add code to that sheet. Although it worked fine in "step through", in practice, the sheet was not added until the macro had completed, and the AddCode was "missed"
    MD

  9. #9
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Changing the timing, by splitting the code, does not always work.
    Tried that many times, not always successful.

    In the real applications in which I have encountered the problem, the code was not always so close together, so there's no simple timing solution.
    I constructed the example to exacerbate the timing aspect.

  10. #10
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    The problem was not discovered by moi alone, a number of others also reported/confirmed the problem.

    It's clearly a timing issue, Word has this worse than the other Office apps, so a "general" solution ain't so easy. Users would not be happy of macros included long wait loops.

    I wonder if the problem is going to get worse when Office is .NET-ized as garbage collection is very different in .NET. Wow, think of all the new bugs we will have to investigate! Something to look forward too!

  11. #11
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by mdmackillop
    Hi,
    I couldn't replicate it either (Word 2000). I agree the delete and remake are too close together and this may cause the problem. Things don't always happen in "real life" as they do in stepping through a macro. I would allocate Delete Tooolbar to a DocumentOpen event in the template
    MD
    In the general case that won't work as one does not always easily know WHEN the toolbar will need to be deleted.

    The posted example was constructed to exacerbate the problem.

  12. #12
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    May not be relevant but, in playing with this, I ended up at one point with three copies of the toolbar - all invisible. I deleted them all through Tools > Customize and closed Word and restarted and they were all still there.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  13. #13
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Sorry, should have said DocumentClose event.
    MD

  14. #14
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by TonyJollans
    May not be relevant but, in playing with this, I ended up at one point with three copies of the toolbar - all invisible. I deleted them all through Tools > Customize and closed Word and restarted and they were all still there.
    Ayup, that is also how I encountered the problem several years ago.

  15. #15
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by Tommy
    I think this is the problem.

    tempORary:=False

    When the tool bar is created it sets the temporary flag to false. I don't know this but Word may place the information (the toolbar) in a seperate area for permanent tollbars vs temp toolbars.
    My recollection is that I had tested that hypothesis several years ago.

  16. #16
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Temporary = False is the default so explicitly specifying it shouldn't make any difference. If memory serves, there used to be a problem with Temporary=True not working properly, but I think that's now fixed.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  17. #17
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I tested and got 5+ commandbars. I saved changes. I opened Normal.dot and deleted the commandbars. I then changed the Temporary = False to Temporary = True. I now do not get duplicates of the commandbars I just get 1. What am I missing?

  18. #18
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Hey, Tommy. Just to be clear, in which version are you testing?
    ~Anne Troy

  19. #19
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by TonyJollans
    Temporary = False is the default so explicitly specifying it shouldn't make any difference. If memory serves, there used to be a problem with Temporary=True not working properly, but I think that's now fixed.
    I sometimes specify certain defaults as that makes the code clearer.

    In addition, specifying the defaults eliminates bugs due to MSFT changing defaults from version to version, rarely done, but it'd cheap protection.

  20. #20
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Howard,

    MS Bugs - surely not!!
    Tommy,

    Temporary=True, if it works, means that the toolbars never get saved, no matter how many there are
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

Posting Permissions

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