Macros in Outlook

Macros in Outlook

Postby driessen » Mon Jul 22, 2024 7:53 pm

Hello,

In my application I use macros in Word : oWord:Run("Macro").

So far so good.

Now I need to run a macro in Outlook and tried it the same way : oOutlook:Run("MacroOutl").
But here I get an error saying that the export method "RUN" doesn't exist.

How do I run a macro in Outlook from my FWH-application?

Thanks a lot for any help.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Macros in Outlook

Postby Antonio Linares » Tue Jul 23, 2024 6:05 am

Dear Michel,

Please try this:

oOutlook:Application:RunMacro( "MacroOutl" )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Macros in Outlook

Postby driessen » Tue Jul 23, 2024 7:10 am

Dear Antonio,

Thanks for your reaction.

I tried your suggestion but I got an error : WINOLE/1009 No exported method: RUNMACRO

I also tried: oOutlook:Application:Run( "MacroOutl" )

But unfortunately I got the same error : WINOLE/1009 No exported method: RUN

Any further suggestions?
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Macros in Outlook

Postby Otto » Tue Jul 23, 2024 8:00 am

Hello Michel,

I found some code in my own programs - this worked for me:

Code: Select all  Expand view


FUNCTION InFolder()

   local oOutlook := CREATEOBJECT( "Outlook.Application" )
   local oNameSpace := oOutlook:GetNameSpace("MAPI")
   local oInbox := oNameSpace:GetDefaultFolder( olFolderInbox )

   local i

   FOR i = 1 TO oInbox:Items:Count
      msginfo( oInbox:Items[ i ]:Body )
   NEXT

   oOutlook:Quit()

RETURN NIL

 


And read you have to use for RUN - maybe this helps? - not tested:
And you have:

Outlook is installed on the machine where this code runs.
Security settings allow macros to run and the VBA project object model is accessible (Trust Center settings in Outlook)





Code: Select all  Expand view
LOCAL oOutlook
LOCAL oNamespace
LOCAL oModule

TRY
    // Create Outlook application object
    oOutlook := CreateObject("Outlook.Application")

    // Get the MAPI namespace
    oNamespace := oOutlook:GetNamespace("MAPI")

    // Get the VBProject of Outlook
    oModule := oOutlook:VBProject:VBComponents("Module1") // Adjust "Module1" to the name of your module

    // Run the macro
    oOutlook:Run("'" + oModule.Name + ".MacroOutl'")

CATCH
    // Handle errors
    MsgInfo("An error occurred while trying to run the macro.")
END

// Release the Outlook object
oOutlook := NIL


Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Macros in Outlook

Postby karinha » Tue Jul 23, 2024 3:42 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Macros in Outlook

Postby driessen » Tue Jul 23, 2024 3:52 pm

Hello guys,

Very interesting information.

I'm going to do some test tomorrow and let you know the results.

Thank you all very much.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Macros in Outlook

Postby driessen » Wed Jul 24, 2024 1:42 pm

Hello Otto,

This is the code I use:
Code: Select all  Expand view
jOutlook   := TOleAuto():New("Outlook.Application")
jNameSpace := jOutlook:GetNameSpace("MAPI")
jEmail     := jOutlook:CreateItem(olMailItem)
jModule    := jOutlook:VBProject:VBComponents("Module1")
jOutlook:Run("'"+jModule:Name+".PasteClipboardInNewEmail'")
And this is the error I get:
Application
===========
   Path and name: M:\SOFTWARE\JUDA\JUDA_2_D.EXE (32 bits)
   Size: ********* bytes
   Compiler version: xHarbour 1.2.3 Intl. (SimpLex) (Build 20190614)
   FiveWin  version: FWH 24.04
   C compiler version: Pelles ISO C Compiler 3.0 (32-bit)
   Windows 11 64 Bits, version: 6.2, Build 9200

   Time from start: 0 hours 19 mins 53 secs
   Error occurred at: 24/07/2024, 15:34:08
   Error description: Error Outlook.Application/0  S_OK: VBPROJECT
   Args:

Stack Calls
===========
   Called from:  => TOLEAUTO:VBPROJECT( 0 )
   Called from: C:\SOFTWARE\JUDA\PRG\FGEGTL1.PRG => SENDMAIL( 3771 )
   Called from: C:\SOFTWARE\JUDA\PRG\DOCWP2.PRG => EMAILDOC( 5457 )
   Called from: C:\SOFTWARE\JUDA\PRG\JUDA.PRG => MAILSEND( 3309 )
   Called from: C:\SOFTWARE\JUDA\PRG\FGEGTL2.PRG => (b)BUILDBAR1( 3401 )
   Called from: .\source\classes\btnbmp.prg => TBTNBMP:CLICK( 809 )
   Called from: .\source\classes\btnbmp.prg => TBTNBMP:LBUTTONUP( 1096 )
   Called from: .\source\classes\control.prg => TCONTROL:HANDLEEVENT( 1851 )
   Called from: .\source\classes\btnbmp.prg => TBTNBMP:HANDLEEVENT( 2173 )
   Called from: .\source\classes\window.prg => _FWH( 1000 )
   Called from:  => WINRUN( 0 )
   Called from: .\source\classes\window.prg => TWINDOW:ACTIVATE( 1114 )
   Called from: C:\SOFTWARE\JUDA\PRG\JUDA.PRG => MAIN( 1012 )
Any idea why I get this error?

What do I want to do? I copy the text of a Word-document into the clipboard.
And I want to paste this this text into the body of the new created e-mailmessage.

Thanks a lot.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Macros in Outlook

Postby Otto » Wed Jul 24, 2024 2:42 pm

Hello Michel,
this works for me.
Best regards,
Otto

Code: Select all  Expand view

#include "FiveWin.ch"

static oDlg, oClp

function Main()
   
    DEFINE DIALOG oDlg ;
        TITLE "Send email" ;
        FROM 6, 6 ;
        TO 30, 60
   
    DEFINE CLIPBOARD oClp OF oDlg
   
    @ 3, 2 BUTTON "Send Email - Text from Clipboard" OF oDlg ;
        ACTION ( EXEC_EMAILSENDEN() )
       
    @ 6, 2 BUTTON "&Bye!" OF oDlg ACTION oDlg:End()
   
    ACTIVATE DIALOG oDlg ;
        VALID MsgYesNo( "Want to end ?" )
   
return nil

//----------------------------------------------------------------------------//

function EXEC_EMAILSENDEN( )
   
    local oMail, oOutlook, oNameSpace, oAttachment
    local cMailTo           := "winhasdfotefe@fests.at"  
    local cBetreff      := "Test Clipboard"  
    local cHTMLBody         :=  ""
    local cHTMLContent  := ""
    local cText             := ""
   
    cText := oClp:GetText()
   
    #define olMailItem 0
    #define olFormatHTML 2
   
    oOutlook    := CREATEOBJECT("Outlook.Application")
    oNameSpace  := oOutlook:GetNameSpace("MAPI")
    oMail       := oOutlook:CreateItem(olMailItem)
    oMail:Subject := cBetreff
    oMail:BodyFormat := olFormatHTML
   
   
    cHTMLContent := '<h1>test</h1><p>The new cafeteria is open...</p><br>' + cText + 'Ende'
       
   
    oMail:HTMLBody = cHTMLContent
   
    oMail:To := cMailTo
    oMail:Display = .F.
    oMail:Send()
   
    oMail := NIL
   
    ? "gesendet"
   
RETURN NIL
//----------------------------------------------------------------------------//
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Macros in Outlook

Postby driessen » Wed Jul 24, 2024 3:10 pm

Otto,

Thank you very much for your suggestion.

My first tests look very promessing.

The first results are very good.

Thank you once again.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Macros in Outlook

Postby Otto » Wed Jul 24, 2024 3:59 pm

Michel,
If you also need to include images, then I think you first need to split the clipboard content and link the images separately. This part is only for text.

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 89 guests