View Full Version : Calling Outlook Macro From Excel
smithani
11-19-2008, 08:50 AM
I have a macro in outlook which saves attachments from new emails based on certain criteria.
I also have a macro in excel which edits these files once they have been saved.
How can I call the outlook macro (GetAttachments) from my excel macro?
JoeMarfice
11-20-2008, 02:13 PM
According to this link:
http://help.lockergnome.com/office/Call-macro-stored-Excel-workbook-Outlook-macro-ftopict877683.html
you use:
Call Outlook.Application.TestMacro("test@test.com", "Test","C:\test.xls")
A little more digging suggested that you needed to open an Outlook.Application item first:
Function OpenOL(Optional ProfileName) As Outlook.Application
Dim objOL As Application Outlook.Application
On Error Resume Next
Set objOL = GetObject(, "Outlook.Application")
If objOL Is Nothing Then
Set objOL = CreateObject("Outlook.Application")
objOL.Session.Logon ProfileName, , False, True
End If
Set OpenOL = objOL
Call OpenOL.TestMacro
Set objOL = Nothing
End Function
However, when I run it I receive an error that Outlook.Application is an unknown object. I tried commenting out the offending words "Outlook.Application", but it still doesn't work (it does run without error, however).
HTH, a little, at least.
flyfisher15
01-23-2012, 10:47 AM
I'd love some help on this too. I'm trying to do something very similar to this. and having the same type of error.
JP2112
01-23-2012, 01:17 PM
How about this?
http://blogs.msdn.com/b/sachinsancheti/archive/2006/05/16/598951.aspx
Or this?
http://stackoverflow.com/questions/6910865/open-outlook-macro-with-excel-vba
gvreddyhr
01-20-2015, 06:25 AM
Hello Smithani,
Can you able to get through the above macro, as am looking for the same macro where in the criteria's are given in excel and wanted to save the attachments in specified path.
Request you to share the macro which you could have created, Appreciate your response.
thanks in advance
Regards,
guru
gmayor
01-20-2015, 07:09 AM
However, when I run it I receive an error that Outlook.Application is an unknown object. I tried commenting out the offending words "Outlook.Application", but it still doesn't work (it does run without error, however).
Outlook would be an unknown object unless you tell Excel what Outlook is. You can do this by setting a reference to the Outlook object library in the Excel VBA Editor Tools > References. Or you could use late binding to Excel and change the references in the Function e.g. as follows. As for the running without errors, you have the option set On Error Resume Next.
Function OpenOL(Optional ProfileName) As Object
Dim objOL As Object
On Error Resume Next
Set objOL = GetObject(, "Outlook.Application")
If objOL Is Nothing Then
Set objOL = CreateObject("Outlook.Application")
objOL.Session.Logon ProfileName, , False, True
End If
Set OpenOL = objOL
Call OpenOL.TestMacro
Set objOL = Nothing
End Function
As for the rest, I haven't tested the code.
Have you checked the fuse for the wipers?If the fuse is good then check the wiring from the pump back.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.