Page 1 of 3 123 LastLast
Results 1 to 15 of 36
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Clear Immediate Window

    I know this is an old issue, but I was just wondering if anybody had anything new on using code to clear the Immediate window in the Word 97 IDE. I'd love to be able to put a statement in code, during a debugging phase, that clears the immediate window so that old debug.print results are cleared. Clicking on the windows, pressing Ctrl-A and del is a real bother when I'm trying to concentrate on the code execution.

    Call ClearImmediate 'Like this
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Clear Immediate Window

    Kevin,

    The way I've gotten at lines in the VBE is via the CodeModule property (of ActiveCodePane or SelectedVBComponent), but the Immediate window doesn't appear to have a CodeModule property.

    You can get to the Immediate window via the VBE.Windows collection, but can't do much more than .SetFocus, which gets the cursor in there anyway.

    So using that, here's a SendKeys method that does work - use it at your own risk! (might want to add an On Error Resume Next statement in there just for insurance...)

    VBE.Windows("Immediate").SetFocus
    SendKeys "+{UP}" 'this selects everything, somehow...
    SendKeys "{DEL}"

    Gary

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Clear Immediate Window

    > SendKeys "+{UP}" 'this selects everything, somehow...

    Not in MY Word97SR2/VBA.

    I wasn't sure why Shift-Up arrow should select everything.

    I tried various combinations for Ctrl-A (which works by hand) such as
    ^A
    ^(A)

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Clear Immediate Window

    This turns out to be very flaky: after I posted this, I tried it again and found it wasn't working. Then it was working. Then it wasn't.

    In the general spirit of trying weird things, I then tried using:

    VBE.Windows("Immediate").SetFocus
    SendKeys "+{UP}" 'this selects everything, somehow...
    SendKeys "{DEL}"
    VBE.Windows("Immediate").SetFocus
    SendKeys "+{UP}" 'this selects everything, somehow...
    SendKeys "{DEL}"

    (just running it twice in the same procedure.)
    Now, it works every time! (well, the 5 times I tried it before I got bored...)

    I have to admit I didn't try the SendKeys for Ctrl+A.

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Clear Immediate Window

    Gary,

    Thanks. I'll try this. I tried the same code (very similar anyway... with Ctrl-A, which did not work.) I'm eager to try this shift-up business.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Clear Immediate Window

    What version of Word did you test this code with?


    It definitely does not work in Word 97. I'm still trying though...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Clear Immediate Window

    Ok, get this. Your VBE.Windows("Immediate").Setfocus did absolutely nothing in my Word 97 IDE.

    So....

    I tried looping thru the collection. That worked!

    Your shift-up did something, but not what you report. I think you have to run it twice or more because Shift-Up only grabs the current line. So I tried Ctrl-Shift-Home to grab all lines from the current line up. It Worked! Also, better move to the end of the window text first, then ^+{Home}

    So....

    Here's the code that works in our climate:
    <pre>Sub ClearImmediate()
    '#Const mDeveloping = False 'Unrem this if not declared elsewhere and if needed
    #If mDeveloping Then
    Dim ideWindow As VBIDE.Window
    #Else
    Dim ideWindow As Object
    #End If

    For Each ideWindow In VBE.Windows
    If ideWindow.Caption = "Immediate" Then
    ideWindow.SetFocus
    SendKeys "^{End}"
    SendKeys "^+{Home}"
    SendKeys "{DEL}"
    End If
    Next
    Set ideWindow = Nothing

    End Sub
    </pre>


    I loathe Sendkeys just as much as the next guy, but this code appears to work quite reliably, and if *anybody* can find any property/method/trick in the object model that can do this I'll gladly abandon the key pusher code!

    Please test this for me. Chris, you too. And anyone else who would like to give some feedback. Do we have a "universal" ClearImmediate sub here, or not?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  8. #8
    5 Star Lounger
    Join Date
    Dec 2000
    Location
    Reading/Swindon, Berkshire, United Kingdom
    Posts
    664
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Clear Immediate Window

    depends what you mean by universal. If we're talking Excel, in 97 i had to change

    For Each ideWindow In VBE.Windows

    to

    For Each ideWindow In Application.VBE.Windows

    (I was getting a run time error 429: "activex component can't create object" without this) -otherwise it works fine, and that's not a major change.

    Brooke

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Clear Immediate Window

    Hey, that's pretty cool. Being explicit with 'Application' is better form, anyway. Thanks for feedback Brooke. I'll update mine too.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  10. #10
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Clear Immediate Window

    Good on ya, mate.
    This works in both my Word 97 and Word 2K setups, so I'll take two copies, please.

    Since you can only get to the Immediate Window as a window (and not a code module), and since you can't access the code via the window object, it's a safe bet that this is as good as it gets.

    For something that's never going to be used outside my own VBE, I couldn't care less if it uses SendKeys, trained egrets or whatever!

  11. #11
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Clear Immediate Window

    Well, after further testing, I'm finding this little module is not all it's cracked up to be.

    Put the statement

    Call ClearImmediate

    in a module you are testing. Put some junk in the immediate window. Run the module. Did the ClearImmediate code clear the immediate window? Not me for. Grand bummer. <img src=/S/flee.gif border=0 alt=flee width=25 height=25> <img src=/S/fire.gif border=0 alt=fire width=15 height=15> <img src=/S/smash.gif border=0 alt=smash width=30 height=26>

    Finicky.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  12. #12
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Clear Immediate Window

    Gary,

    More testing, please. See my previous post to myself (which you may have missed).

    Thanks for the feedback from down under. Good to know you are having some success in your zone. But see my post, please.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  13. #13
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Clear Immediate Window

    HA!

    I added

    ideWindow.Visible = true

    and it worked from a code call!

    <pre>Sub ClearImmediate()
    #If mDeveloping Then
    Dim ideWindow As VBIDE.Window
    #Else
    Dim ideWindow As Object
    #End If

    For Each ideWindow In Application.VBE.Windows
    If ideWindow.Caption = "Immediate" Then
    ideWindow.SetFocus
    ideWindow.Visible = True
    SendKeys "^{End}"
    SendKeys "^+{Home}"
    SendKeys "{Del}"
    End If
    Next
    Set ideWindow = Nothing

    End Sub</pre>

    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  14. #14
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Clear Immediate Window

    By 'down under' are you referring to the placement of the Immediate window on my screen?<g> - this missive comes to you straight from the corporate epicenter of NYC (maybe you are referring to the subway?).

    Don't know whether you'll find this disappointing, but your earlier version is still working fine for me! Setting the window to visible certainly wouldn't hurt though.

    By the way you don't need the "Call" keyword when you call ClearImmediate, since you're not passing it any arguments (but I know you know that <img src=/S/grin.gif border=0 alt=grin width=15 height=15>)

    BTW I just learned something new: if I make a mistake while typing in the Immediate window, and reflexively try Ctrl+Z to undo it, what gets undone is the last change I made up in the "real" code module <img src=/S/doh.gif border=0 alt=doh width=15 height=15>.

  15. #15
    5 Star Lounger
    Join Date
    Dec 2000
    Location
    Reading/Swindon, Berkshire, United Kingdom
    Posts
    664
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Clear Immediate Window

    I don't need to set .visible = true in excel to call it from other code but as you've both said, that won't hurt.

Page 1 of 3 123 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
  •