• Welcome to Theos PowerBasic Museum 2017.

Outlook 11 should be simple

Started by John Petty, May 10, 2009, 08:25:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

John Petty

Hope I am in the right forum as am still using PB 8.03 Typelib Browser 2.05 (which saved me much trouble once). So now one of my rare excursions into COM. Short background, I have seen that spam senders are now managing to avoid Outlooks junk mail filter plus travelling a bit again so not wanting the nuisance value of the spam while on WebMail have written a fast simple Spam Filter program (so far 99% effective has a simple test Outlook doesn't use). So instead of Outlook checking for mail every few minutes I wanted my program to check first then tell outlook (if running) to do a send receive. In VB it would be easy ie oApp.ActiveExplorer.CommandBars("Standard").Controls("Send/Re&ceive").Execute.
The PB 8.03 com browser as it has loads of "AS type" with no definition of the the types. In 2.05 I get a little further ActiveExplorer calls another interface _explorers which it says then references a coclass of CommandBars which doesn't appear in the coclass listings. Any advice would be appreciated.

José Roca

 
CommandBars and other interfaces are in the Microsoft Office Object Library (MSO.DLL).

The following code is an step by step translation of the VB one that you have posted. It works in my computer until the Execute method is called, that returns an exception (no idea why, I don't have any expertise programming Office applications).


FUNCTION PBMAIN () AS LONG

   LOCAL oApplication AS DISPATCH
   LOCAL oExplorer AS DISPATCH
   LOCAL vExplorer AS VARIANT
   
   oApplication = NEW DISPATCH IN "Outlook.Application.11"
MSGBOX "oApplication = " & STR$(OBJPTR(oApplication))
   IF ISNOTHING(oApplication) THEN EXIT FUNCTION
   
   OBJECT CALL oApplication.ActiveExplorer TO vExplorer
   IF VARIANT#(vExplorer) = 0 THEN EXIT FUNCTION
   oExplorer = vExplorer
MSGBOX "oExplorer = " & STR$(OBJPTR(oExplorer))
   IF ISNOTHING(oExplorer) THEN EXIT FUNCTION

   LOCAL vDispatch AS VARIANT
   LOCAL oCommandBars AS DISPATCH
   OBJECT GET oExplorer.CommandBars TO vDispatch
   oCommandBars = vDispatch
   IF VARIANT#(vDispatch) = 0 THEN EXIT FUNCTION
MSGBOX "oCommandBars = " & STR$(OBJPTR(oCommandBars))
   IF ISNOTHING(oCommandBars) THEN EXIT FUNCTION

   LOCAL oCommandBar AS DISPATCH
   LOCAL vCommandBar AS VARIANT
   LOCAL vIdx AS VARIANT
   vIdx = "Standard"
   OBJECT GET oCommandBars.Item(vIdx) TO vCommandBar
   IF VARIANT#(vCommandBar) = 0 THEN EXIT FUNCTION
   oCommandBar = vCommandBar
MSGBOX "oCommandBar = " & STR$(OBJPTR(oCommandBar))
   IF ISNOTHING(oCommandBar) THEN EXIT FUNCTION
   
   LOCAL oCommandBarControls AS DISPATCH
   LOCAL vCommandBarControls AS VARIANT
   OBJECT GET oCommandBar.Controls TO vCommandBarControls
   IF VARIANT#(vCommandBarControls) = 0 THEN EXIT FUNCTION
   oCommandBarControls = vCommandBarControls
MSGBOX "oCommandBarControls = " & STR$(OBJPTR(oCommandBarControls))
   IF ISNOTHING(oCommandBarControls) THEN EXIT FUNCTION

   LOCAL vCommandBarControl AS VARIANT
   LOCAL oCommandBarControl AS DISPATCH
   vIdx = "Send/Re&ceive"
'   vIdx = "Enviar y re&cibir"  ' --> Spanish version
   OBJECT GET oCommandBarControls.Item(vIdx) TO vCommandBarControl
   IF VARIANT#(vCommandBarControl) = 0 THEN EXIT FUNCTION
   oCommandBarControl = vCommandBarControl
MSGBOX "oCommandBarControl = " & STR$(OBJPTR(oCommandBarControl))
   IF ISNOTHING(oCommandBarControl) THEN EXIT FUNCTION
   
   OBJECT CALL oCommandBarControl.Execute

MSGBOX HEX$(OBJRESULT)

END FUNCTION


John Petty

Jose
Thank you for the time you spent on this, thought you might like an update. Spent hours trying to look through the documentation of all the interfaces and collections. Finally gave up and went "old fashioned". Checked if Outlook was running, activated it and sent F9 with KEYBD_EVENT. Is simple and works perfectly.
Again thanks
John