Results 1 to 7 of 7

Thread: Send Keys to Outlook from VB

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Send Keys to Outlook from VB

    Anyone know how to send Ctl + G to Outlook from a vb project?
    I really dont want to be using VBA or the SendKeys function.



    Thanks in advance.

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Sice I cannot test, what's CTL+G in Outlook?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  3. #3

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Under the Calendar display the menu will change so if you press Ctl + G you will get the
    Go To Date... dialog box.
    This will display that days appointments.
    Also, you can go there by clicking on "View - Go To - Go To Date..."
    I guess it doesn't matter what your sending and to where
    I just need to figure it out, so any example should do just fine.

  4. #4
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    AppActivate "Outlook"
    ' NOTE Above statement will NOT work. Outlook changes its title, depending on what folder is selected.
    SendKeys "^g"

    There is also an API that does something similar to SendKeys - but I don't use it / know it.

    The alternative is to call Outlook from your VB program, and either get your program to display the information you want, or ask Outlook (typically via <SomeObject>.DISPLAY) to dispay it for you.

  5. #5

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    What about finding the process ID of Outlook by going through
    the task manager with some APIs and then using the
    FindWindowEx API then using the SendMessage API?

  6. #6

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Outlook is always listed in the task manager as "OUTLOOK.EXE"
    I have coded finding a process before by name, but I havent used the
    FindWindowEx or SendMessage APIs.

    Any Help on these?

  7. #7
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    I don't know if I will include everything needed, but here is some extracts that I use to ENUM through open Windows, and identify which one is Outlook:

    VB Code:
    1. '
    2. ' Declarations to handle "What was the last app used?"
    3. '
    4. Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
    5. Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    6. Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    7. Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    8. Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
    9.                 (ByVal hwnd As Long, ByVal lpClassName As String, _
    10.                 ByVal nMaxCount As Long) As Long
    11. Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    12.  
    13. Public thisHwnd As Long
    14. Public LastApp As Long
    15. Public LastAppTitle As String
    16. Public LastAppClass As String
    17. Public Declare Function GetActiveWindow Lib "user32" () As Long
    18. Public Const WM_CLOSE = &H10
    19. Public Const INFINITE = &HFFFFFFFF
    20. '
    21. ' Now some code to use them
    22. '
    23. Public Function WhoCalledUs()
    24.     thisHwnd = GetActiveWindow()
    25.     LastApp = 0
    26.     Call EnumWindows(AddressOf EnumWinProc, 0)
    27.     Select Case LastAppClass
    28.         Case "OpusApp"
    29.             WhoCalledUs = "Word"
    30.         Case "XLMAIN"
    31.             WhoCalledUs = "Excel"
    32.         Case "rctrl_renwnd32"
    33.             WhoCalledUs = "Outlook"
    34.         Case "ExploreWClass"
    35.             WhoCalledUs = "WinExp"
    36.         Case "PP9FrameClass"
    37.             WhoCalledUs = "PPT"
    38.         Case Else
    39.             WhoCalledUs = ""
    40.     End Select
    41. End Function
    42.  
    43. Public Function EnumWinProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    44.     Dim lRet, lWindowStyle, lWindowParent As Long
    45.     Dim strBuffer As String
    46.    
    47. 'Only keep windows that are visible,
    48. ' don't have parents, have a title bar and a caption,
    49. ' and are not this application, and are the first application found
    50.     If hwnd <> thisHwnd Then                            ' Not this app
    51.         If IsWindowVisible(hwnd) Then                   ' Window visible
    52.             lWindowParent = GetParent(hwnd)
    53.             If lWindowParent = 0 Then                   ' No parents
    54.                 lWindowStyle = GetWindowLong(hwnd, GWL_STYLE)
    55.                 If (lWindowStyle And WS_CAPTION) Then   ' Has a caption
    56.                     strBuffer = Space(MAX_LEN)
    57.                     lRet = GetWindowText(hwnd, strBuffer, Len(strBuffer))
    58.                         If lRet Then                    ' Has a title
    59.                             If LastApp = 0 Then
    60.                                 LastApp = hwnd
    61.                                 LastAppTitle = Left(strBuffer, InStr(strBuffer, Chr(0)) - 1)
    62.                                 strBuffer = Space(MAX_LEN)
    63.                                 lRet = GetClassName(hwnd, strBuffer, MAX_LEN)
    64.                                 LastAppClass = Left(strBuffer, InStr(strBuffer, Chr(0)) - 1)
    65.                             End If
    66.                         End If
    67.                 End If
    68.             End If
    69.         End If
    70.     End If
    71.     EnumWinProc = 1
    72. End Function

Posting Permissions

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



Click Here to Expand Forum to Full Width