Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to view special items and change Selection from VBA

1 view
Skip to first unread message

Chris Melville

unread,
May 25, 2000, 3:00:00 AM5/25/00
to

I recently unsuccessfully asked two questions here after failing to
find obvious techniques myself:

1) How to programatically change which item is selected in the current
OL explorer

2) How to programatically open a Winfax fax (as an OL item) into the
Winfax fax viewer, since the .Display method only opens it in a normal
email form showing lots of attachments (one per fax page).

I've now come up with a fairly workable solution, and here's the code
in case anyone else has a similar problem. It basically sends
keystrokes to the active explorer in Outlook to change the selection,
since this doesn't seem possible directly through VBA and the Outlook
object model.

UtilCursor can be called to move the selecttion up/down/home/end, and
it can also activate the currently selected item (hence solving the
second of my two problems if the item is a Winfax fax) through
the "Enter" value.

UtilItemSelect allows you to select any item in the explorer (eg. Inbox
list) if you know it's EntryID (a unique text string - see OL VBA docs
for more info). It's not amazingly efficient, but it's better than the
alternative of nothing (though it could be optimised).

I did this in NT, but it should also work for Win 95/8 (perhaps the
Windows library names need changing in their declarations, but the code
should work).

Note that any use of this technique or code is at your own risk!

Cheers
Chris

====================================== CODE
=====================================

' PRIVATE STUFF
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal
bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Declare Function MapVirtualKey Lib "user32"
Alias "MapVirtualKeyA" (ByVal uCode As Long, ByVal uMapType As Long) As
Long

Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2

Private Const VK_HOME = &H24
Private Const VK_END = &H23
Private Const VK_UP = &H26
Private Const VK_DOWN = &H28
Private Const VK_RETURN = &HD

'PUBLIC STUFF - the APIs

Public Const UC_HOME = 1
Public Const UC_END = 2
Public Const UC_UP = 3
Public Const UC_DOWN = 4
Public Const UC_ENTER = 5

Sub UtilCursor(where As Integer)
Dim vk As Long, sc As Long, hProcess As Long

Select Case where
Case UC_HOME
vk = VK_HOME
Case UC_END
vk = VK_END
Case UC_UP
vk = VK_UP
Case UC_DOWN
vk = VK_DOWN
Case UC_ENTER
vk = VK_RETURN
End Select

sc = MapVirtualKey(vk, 0)

' Send key up and down events to Windows, for Outlook
keybd_event vk, sc, KEYEVENTF_EXTENDEDKEY, 0
keybd_event vk, sc, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
'This is needed so queued keyboard events actually get to Ootlook
and change things in it
DoEvents
End Sub


Function UtilItemSelect(TargID As String)

Dim s, lastEntryID As String
lastEntryID = ""
Set s = Application.ActiveExplorer.Selection
Call UtilCursor(UC_HOME)

While (s.Count = 1) And (s.item(1).EntryID <> TargID) And (s.item
(1).EntryID <> lastEntryID)
lastEntryID = s.item(1).EntryID
Call UtilCursor(UC_DOWN)
Set s = Application.ActiveExplorer.Selection
Wend

UtilItemSelect = (s.item(1).EntryID = TargID)

End Function


Sent via Deja.com http://www.deja.com/
Before you buy.

0 new messages