Consulting

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

Thread: Challenge!! Can you solve this problem?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 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.

  7. #7
    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

  8. #8
    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!

  9. #9
    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.

  10. #10
    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.

  11. #11
    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

  12. #12
    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.

  13. #13
    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

  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
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    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.
    Had the same thing...I still think the problem is timing, but exacerbated by the fact that there is actually no macro/module in the workbook being used. The macro is in the template and is being referenced by the workbook and what happens in one is not neccessarily being duplicated in the other at the same time (this is instanced by the fact that you can rename, change, and save, the workbook but on exiting the book you will then be asked if you want to save the template)

  16. #16
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by johnske
    Had the same thing...I still think the problem is timing, but exacerbated by the fact that there is actually no macro/module in the workbook being used. The macro is in the template and is being referenced by the workbook and what happens in one is not neccessarily being duplicated in the other at the same time (this is instanced by the fact that you can rename, change, and save, the workbook but on exiting the book you will then be asked if you want to save the template)
    We need to stick to Word in this thread, Excel is usually not as misbehaving as Word.

  17. #17
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by johnske
    ....timing, but exacerbated by the fact that there is actually no macro/module in the (DOC) being used. The macro is in the template and is being referenced by the (DOC) and what happens in one is not neccessarily being duplicated in the other at the same time....
    Re: My last post (quoted above) anyone else wanna try this?
    1) export the module from the template
    2) move the template to the recycle bin
    3) now import the module into the document
    4) goto tools/references and untick any reference to the template
    5) disable CustomizationContext = NormalTemplate by putting an apostrophe in front of it
    6) save...
    Now run the macro (delete & instant remake) and see if you get any duplications

    I did and couldn't get any....

  18. #18
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by johnske
    Re: My last post (quoted above) anyone else wanna try this?
    1) export the module from the template
    2) move the template to the recycle bin
    3) now import the module into the document
    4) goto tools/references and untick any reference to the template
    5) disable CustomizationContext = NormalTemplate by putting an apostrophe in front of it
    6) save...
    Now run the macro (delete & instant remake) and see if you get any duplications

    I did and couldn't get any....
    Is not your code using Temporary=True?
    If so, that ignores the problem, and is not a solution.

  19. #19
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by Howard Kaikow
    Is not your code using Temporary=True?
    If so, that ignores the problem, and is not a solution.
    Sorry, nope...I'm using Temporary=False

  20. #20
    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

Posting Permissions

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