Monday, July 16, 2018

vba - Calling Outlook Script by using an Excel Macro



I have encountered issues where an Outlook rule that is set to run a VBA script would sporadically run into errors. I know the script works because I've tested the script as a Public Sub and I've tested my rule. However, I need my rule to run successfully 100% of the time.



I don't know why my rule encounters errors since there is no error description for Outlook rule failures. So for a workaround, I decided to get my Outlook script running by calling it from Excel. However, I can't get the right connections yet. Can someone please help me run my Outlook VBA script from Excel?




The error I receive is: Run-time error '438'. Object doesn't support this property or method.



The references I have on Excel are:




  1. Visual Basic For Applications

  2. Microsoft Excel 16.0 Object Library

  3. OLE Automation

  4. Microsoft Office 16.0 Object Library

  5. Microsoft Outlook 16.0 Object Library




Outlook references are:




  1. Visual Basic For Applications

  2. Microsoft Outlook 16.0 Object Library

  3. OLE Automation

  4. Microsoft Office 16.0 Object Library

  5. Microsoft Form 2.0 Object Library


  6. Microsoft Excel 16.0 Object Library



Below is the code for Excel:



Public Sub testexcel()

Dim o As Outlook.Application

On Error Resume Next

Set o = GetObject("", "Outlook.Application")
Err.Clear: On error GoTo 0

If o Is Nothing then
Set o = CreateObject("Outlook.Application")
End If

With o
.Session.Logon
.Run "testoutlook" <--------- Error Line

End With

o.Close
o.Quit

Set o = Nothing

End Sub



Outlook sample code:



Public Sub testoutlook()

Call MsgBox("HellO")

End Sub

Answer



After further research, I believe that the VBA coding compatibility between Outlook and Excel don't have developer functionality. However, I was able to complete my task by taking my VBA macro from Outlook and inserting into an Excel book.




Essentially, I removed any VBA coding from Outlook so everything was able to be completed using Excel. If anyone is interested in the codes please let me know.


No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...