Consulting

Results 1 to 7 of 7

Thread: Calling Outlook Macro From Excel

  1. #1
    VBAX Newbie
    Joined
    Nov 2008
    Posts
    2
    Location

    Calling Outlook Macro From Excel

    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?

  2. #2
    According to this link:
    http://help.lockergnome.com/office/C...ict877683.html
    you use:

    [VBA] Call Outlook.Application.TestMacro("test@test.com", "Test","C:\test.xls") [/VBA]

    A little more digging suggested that you needed to open an Outlook.Application item first:

    [VBA]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
    [/VBA]

    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.

  3. #3
    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.

  4. #4

  5. #5
    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

  6. #6
    Quote Originally Posted by JoeMarfice View Post
    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.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  7. #7

    Calling Outlook Macro From Excel

    Have you checked the fuse for the wipers?If the fuse is good then check the wiring from the pump back.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •