I have been using R's RDCOMClient package to manipulate Excel files and it has been a tremendous help.
Now I am venturing on to using Outlook and have learned how to send mail using the thread here
However, I want to use R's RDCOMClient to retrieve messages from my inbox.
In general, we can convert VBA code for use with RDCOMClient, though I am having trouble in certain cases with proper syntax.
i.e. when to access a member of an object using Object[["example"]] or Object$example(); and how to make something like Object$example(test$()) work.
More specifically, how would I convert the following code from MSDN on retrieving mail using VBA?
Dim outlookNameSpace As Outlook.NameSpace
Dim inbox As Outlook.MAPIFolder
Dim WithEvents items As Outlook.Items
Private Sub ThisAddIn_Startup() Handles Me.Startup
outlookNameSpace = Me.Application.GetNamespace("MAPI")
inbox = _
outlookNameSpace.GetDefaultFolder( _
Outlook.OlDefaultFolders.olFolderInbox)
items = inbox.Items
End Sub
Private Sub Items_ItemAdd(ByVal item As Object) Handles items.ItemAdd
Dim filter As String = "USED CARS"
If TypeOf (item) Is Outlook.MailItem Then
Dim mail As Outlook.MailItem = item
If mail.MessageClass = "IPM.Note" And _
mail.Subject.ToUpper.Contains(filter.ToUpper) Then
mail.Move(outlookNameSpace.GetDefaultFolder( _
Outlook.OlDefaultFolders.olFolderJunk))
End If
End If
End Sub
Here I made some attempts in R like:
OL = COMCreate("Outlook.Application")
outlookNameSpace = OL$GetNameSpace("MAPI")
with ideas of following the logic presented in the VBA code. However, I run into the problems mentioned above where the syntax for accessing members and methods is not easily translated.
subpath = OL$OlDefaultFolders()$olFolderInbox()
##Or something like
subpath = OL$DefaultFolders()
subpath2 = subpath$olFolderInbox()
Ultimately, my question (and one potentially posed by others) can be best by a direct conversion of the MSDN example from VBA to R, or a link to a comprehensive tutorial.
And for the record I have already read this great tutorial on RDCOMClient
I appreciate any help you can give me, and I think this topic would be a great launchpad for general VBA -> RDCOM ideas