Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: Who is Me?

  1. #1
    kelliel
    Guest

    Who is Me?

    I guess I don't understand "Me" and its usage. I found the following code at <A target="_blank" HREF=http://abstractvb.com>http://abstractvb.com</A>.

    <pre>Add the following code to a BAS Module:

    Declare Function LockWindowUpdate Lib "user32" _
    (ByVal hWnd As Long) As Long

    Public Sub LockWindow(hWnd As Long, blnValue As Boolean)
    If blnValue Then
    LockWindowUpdate hWnd
    Else
    LockWindowUpdate 0
    End If
    End Sub

    Then call the code like this:

    LockWindow me.hwnd, True 'To turn it on

    OR

    LockWindow me.hwnd, False 'To Turn it off
    </pre>


    When I attempt to call from code I receive an error: "Invalid use of the Me keyword."

    I guess I don't understand Me.

    <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15> <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15>

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

    Re: Who is Me?

    In native VBA me always refers to the userform name. Instead of coding

    frmUserForm.combo1.text = "Hi there."

    you can

    me.combo1.txt....

    In VB (which is where your example comes from) Me refers to the current (active) Window -- which is not a supported use of the ME keyword in VBA.

    This is my understanding anyway.

    Why not just use Application.screenupdating = false?
    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>

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Who is Me?

    The quoted code will lock a particular window rather than the entire screen, which is sometimes handy. Me actually refers to the current class module, which includes the ones behind forms and (in Access) reports.
    Charlotte

  4. #4
    calacuccia
    Guest

    Re: Who is Me?

    Me in Word or Excel VBA also refers to ThisWorkbook, Sheet or ThisDocuemtn class modules.

    In a Sheet module you can use Me to refer to the sheet, in ThisWorkbook, me can be used to refer to the Workbook.

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Who is Me?

    When you say lock the window, what do you mean?
    I am looking for a way to launch an application (word or whatever) from an app and make it modal so that it is not possible to go back to my app to launch anything else until any current application is closed.
    Is this what i am looking for or do i need to use the zorder?

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Who is Me?

    hey, i just noticed i look a lot like calacuccia !! <img src=/S/nuts.gif border=0 alt=nuts width=15 height=15>

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Who is Me?

    It means locking the update for that screen and has nothing to do with modality directly.
    Charlotte

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Who is Me?

    And in a user-defined class module, me refers to the class instance.
    Charlotte

  9. #9
    calacuccia
    Guest

    Re: Who is Me?

    <OFF THREAD>

    Yep, Fatherjack. You sure do <img src=/S/joy.gif border=0 alt=joy width=23 height=23>

    You'll need some exercise with the tongue though.

    <BACK TO THREAD>

  10. #10
    kelliel
    Guest

    Re: Who is Me?

    I was asked if why don't I use application.screenupdating = false?

    I do. However, it does not appear to keep all the screenupdating from happening. There appears to be some other factors that override it.

    Therefore, when I saw the above code, I thought this may be the answer.

    So, now that Me in VBA refers to something besides the Window, is there some way that I can make this work?

  11. #11
    calacuccia
    Guest

    Re: Who is Me?

    Hi Kelliel,

    Try this:

    Declare Function LockWindowUpdate Lib "user32" _
    (ByVal hWnd As Long) As Long

    Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    Private Function ThisHandle() As Long
    'Necessary because most Office applications can handle multiple instances
    Application.Caption = "New Caption Supplied by Program"
    Dim hWndXl As Long
    ThisHandle = FindWindow("XLMAIN", Application.Caption)
    Application.Caption = Empty 'Set the original caption back
    End Function


    Public Sub LockWindow(hWnd As Long, blnValue As Boolean)
    If blnValue Then
    LockWindowUpdate hWnd
    Else
    LockWindowUpdate 0
    End If
    End Sub


    Sub Test()
    LockWindow ThisHandle, True
    ActiveSheet.Range("A1") = "Kelliel"
    MsgBox "Is it updated"
    LockWindow ThisHandle, False
    End Sub

  12. #12
    kelliel
    Guest

    Re: Who is Me?

    Thank you, Thank you, Thank you, Thank you, Thank you, Thank you. <img src=/S/bow.gif border=0 alt=bow width=15 height=15>

    (Get the picture that I am very grateful?)

    I was looking for the FindWindow API because I had used in the past (about 5 years ago). The problem was that I couldn't remember the name.

    Thank you. That worked slicker than slick!

    Now to put it to the real test! Actual working conditions.

  13. #13
    kelliel
    Guest

    Re: Who is Me?

    Thanks to all for assisting me with this. Every message was valuable.

    Between this thread and the thread on error handling, I developed the following usage.

    For those who want to use calacuccia's code, be advised that the line where he has XLMAIN, the XLMAIN needs to be changed to OpusApp. OpusApp is the lpClassName for Word (at least up through Word 97 SR2).

    Near the top of the code which I want to stop the screen from updating (Yes, Application.ScreenUpdating can be used, but as I posted above, it appears to be overridden in certain conditions--which I have not been able to determine), I add the lines:

    <pre>OnError GoTo ErrorHandler
    LockWindow ThisHandle, True</pre>


    Then at the end of the procedure:

    <pre>ExitProcedure:
    Selection.HomeKey wdStory, wdMove

    LockWindow ThisHandle, False
    Application.ScreenRefresh
    Application.ScreenUpdating = True
    Exit Sub

    ErrorHandler:

    Resume ExitProcedure

    Resume

    End Sub
    </pre>


    This produces a totally non-flicker Window, and an Unlock and Refresh should an error occur. (I did try it with Err.Raised and it worked.)

    I will be "fleshing" out the ErrorHandler part of the code by calling a logging/message box/email procedure. But for this example, this suffices.

    BTW, you don't want to leave the window locked! <img src=/S/nope.gif border=0 alt=nope width=15 height=15>

    Not a pretty site! <img src=/S/shocked.gif border=0 alt=shocked width=15 height=15>

    Again, thanks all.

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

    Re: Who is Me?

    Charlotte,

    I'd love to see some code with Me referencing a UDC instance. Would you mind posting some? I've only ever used me in reference to the userform
    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>

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

    Re: Who is Me?

    I always suspected you were going for that Einstein look.
    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>

Page 1 of 2 12 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
  •