Macros in Outlook
Macros in Outlook
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.
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
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
- Antonio Linares
- Site Admin
- Posts: 42268
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Macros in Outlook
Dear Michel,
Please try this:
oOutlook:Application:RunMacro( "MacroOutl" )
Please try this:
oOutlook:Application:RunMacro( "MacroOutl" )
Re: Macros in Outlook
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?
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
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Re: Macros in Outlook
Hello Michel,
I found some code in my own programs - this worked for me:
And read you have to use for RUN - maybe this helps? - not tested:
And you have:
Best regards,
Otto
I found some code in my own programs - this worked for me:
Code: Select all | Expand
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 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
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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
Re: Macros in Outlook
?????
https://fivetechsoft.com/forums/viewtopic.php?t=16631
https://help.utahtech.edu/kb/article/18 ... ok-macros/
Regards, saludos.
https://fivetechsoft.com/forums/viewtopic.php?t=16631
https://help.utahtech.edu/kb/article/18 ... ok-macros/
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Re: Macros in Outlook
Hello guys,
Very interesting information.
I'm going to do some test tomorrow and let you know the results.
Thank you all very much.
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
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Re: Macros in Outlook
Hello Otto,
This is the code I use:And this is the error I get:
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.
This is the code I use:
Code: Select all | Expand
jOutlook := TOleAuto():New("Outlook.Application")
jNameSpace := jOutlook:GetNameSpace("MAPI")
jEmail := jOutlook:CreateItem(olMailItem)
jModule := jOutlook:VBProject:VBComponents("Module1")
jOutlook:Run("'"+jModule:Name+".PasteClipboardInNewEmail'")
Any idea why I get this error?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 )
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
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Re: Macros in Outlook
Hello Michel,
this works for me.
Best regards,
Otto
this works for me.
Best regards,
Otto
Code: Select all | Expand
#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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
Re: Macros in Outlook
Otto,
Thank you very much for your suggestion.
My first tests look very promessing.
The first results are very good.
Thank you once again.
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
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
Re: Macros in Outlook
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
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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************