Consulting

Page 2 of 6 FirstFirst 1 2 3 4 ... LastLast
Results 21 to 40 of 117

Thread: Challenge!! Can you solve this problem?

  1. #21
    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)

  2. #22
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by Tommy
    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?
    The behavior you see is going to vary from version to version.
    And, as I point out in the code comments, the problem does not occur every time the code is run.

    Note that I've NEVER seen the problem with Word 97, so sumptin changed in Word 2000 and beyond.

    Of course, until about a year ago, I was running Office 97 in Win 98, the other versions of Office in Win 2000, so the OS could also be a factor. Maybe the problem will now be seen in Word 97 under Win 2000? Next time I boot to the system with Word 97, I'll try to remember to test, but that may not occur for a looong time.

    In the original app in which I found the problem I was indeed using Temporary=False The example uses Temporary=False to emphasize the problem. After all, a tempory toolbar should vanish on its own anyway.

  3. #23
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    The one at the site that was posted above. I did not download the one John posted.
    I am using Word 2000 9.0.6926 with SP 3. Win98, IE 6 SP1 with all updates installed.

    [VBA]
    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
    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
    Set cmdbar = CommandBars.Add(Name:=strToolbar, Position:=msoBarTop, Temporary:=True, MenuBar:=False) '<-- the line I changed
    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]

    Thing is I did change the temp back to false and was able to reduplicate it. On the commandbar I noticed a funny thing when I looked at the code I saw this tempORary:=False I changed it to true and it went to this Temporary:=True go figure.

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

  5. #25
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Sorry - I meant Doc of course

  6. #26
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Another funny, while testing I had a commandbar set to false and a command button set to true. I changed the commandbar to true, reran the code and when I reopened Word it had 2 buttons on the commandbar.

  7. #27
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    To simplify discussionm do not use Temporary=True.

    Temporary=False must be used as the intent of the original app was to replace an extant toolbar.

    The easiest way was to delete and recreate the toolbar.
    That's when I encountered the problem.

  8. #28
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by Tommy
    Another funny, while testing I had a commandbar set to false and a command button set to true. I changed the commandbar to true, reran the code and when I reopened Word it had 2 buttons on the commandbar.
    I've also seen that behavior, but I didn't want to complicate the example.

    Hey, it's almost 16:00 and I've had no food or drink since about 03:00.
    Is VBAExpress hazardous to my health?

  9. #29
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    If so, Howard, you need only refresh yourself in the arcade.
    ~Anne Troy

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

  11. #31
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    This is very interesting.

    My suspicion is that it is somehow related to the customization context - customizing one template from another seems to be flawed,

    1. Make sure Word is closed
    2. Double click on the DoubleVision template to create a new document based on it
    3. Run the macro - from Word, not the VBE
    4. The toolbar is NOT added to Normal

    I have done this several times and never get the toolbar

    5. Now, click on the New icon open a new document based on Normal
    6. Go back to the document based on doubleVison
    7. Run the macro again, from Word
    8. This time I get a toolbar

    I have repeated this several times, again with consistent results.

    (edited to add this comment - and the related amendments above)
    A bit more testing shows this behaviour only to happen when the macro is run via Alt+F8 from Word - it does not happen when run from within the VBE
    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

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

  13. #33
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by TonyJollans
    This is very interesting.

    My suspicion is that it is somehow related to the customization context - customizing one template from another seems to be flawed,

    1. Make sure Word is closed
    2. Double click on the DoubleVision template to create a new document based on it
    3. Run the macro - from Word, not the VBE
    4. The toolbar is NOT added to Normal

    I have done this several times and never get the toolbar

    5. Now, click on the New icon open a new document based on Normal
    6. Go back to the document based on doubleVison
    7. Run the macro again, from Word
    8. This time I get a toolbar

    I have repeated this several times, again with consistent results.

    (edited to add this comment - and the related amendments above)
    A bit more testing shows this behaviour only to happen when the macro is run via Alt+F8 from Word - it does not happen when run from within the VBE
    CustimizationContext is precisely intended for this purpose.
    However, would not astonish me if there were a "bug"/"feature" depending on HOW the code was run.

    I'll try your experiment a bit later.

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

  15. #35
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by Dreamboat
    If so, Howard, you need only refresh yourself in the arcade.
    I have not played a computer game in over a year.
    I've overcome the addiction!

  16. #36
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    This just gets more and more interesting.
    The peanut gallery is *in attendance*!
    ~Anne Troy

  17. #37
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Best to ignore my last post until I am sure I report what I actually did. It's late here is the only excuse I have.

    It is still interesting.
    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

  18. #38
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by TonyJollans
    Best to ignore my last post until I am sure I report what I actually did. It's late here is the only excuse I have.

    It is still interesting.

    I;ve got about a 2 hour window in which to play.

    I'm gonna start over and document EVERY step.
    Let's see what happens.

  19. #39
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    LOL, Howard. I hope Tony is in bed by now. He's in the UK.
    johnske is down under.
    ~Anne Troy

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

    Inconsistent little beggar aint it?...Went back to your original code and converted it from "Template" to "Normal" and it came back!!!

    Have a look at this attachment, it's in "Normal" with some of your error-handling procedure disabled being the only difference and - for whatever reason - it gives the right results every time.

    But remember that the toolbar(s) are added to ALL your word docs when you add it to one doc, so goto view/toolbars and delete all occurrences of the toolbar before running this...You then only get one toolbar every time

Posting Permissions

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