Reputation: 5958
I would like to know which functions I can use with RDCOMClient objects.
For example, to create an email we can use
OutApp <- COMCreate("Outlook.Application")
# create an email
outMail = OutApp$CreateItem(0)
Along with outMail[["subject"]]
, outMail[["HTMLbody"]]
or outMail[["Attachments"]]$Add(filepath)
But how can I get a comprehensive list?
The RDCOMClient doc is out-of date and the functions listed such as getFuncs()
and getElements()
are not available in the package anymore. Using names()
to try and find out what was under the hood gave me no result, and
install.packages("remotes")
remotes::install_github("omegahat/SWinTypeLibs")
gives an error as well. Any idea on how to check Outlook for objects?
Upvotes: 6
Views: 3150
Reputation: 1276
This can somewhat easily be done for Outlook, because every outlook object has a class
property.
If you have a given object of COMIDispatch
class in R, and it is a reference to an Outlook object, you can use the function class()
to retrieve its class and then check the OlObjectClass enumeration for what properties and methods that class has.
A short step by step example:
> # initialise the app
> Outlook_App <- RDCOMClient::COMCreate("Outlook.Application")
In order to find out what we can do with that object, we need to look up the reference. For that, we need its class.
> Outlook_App$class()
[1] 0
So we look up 0 in the OlObjectClass enumeration and find out it's an Application object. Its properties and methods are listed in the referenced link in the OlObjectClass enumeration: Application.
Here, we have access to the methods and properties. For the events, we would need the now defunct packages RDCOMEvents and/or RDCOMServer.
But we can try the method getNameSpace("MAPI")
to access some other functionality. We know that we have to use the "MAPI" parameter from the method description linked above.
> Outlook_Namespace <- Outlook_App$getNameSpace("MAPI")
Now, the Namepace object has another class, for which we can look up the object definition and so on and so forth.
Unfortunately this does not work for Excel objects, since they do not have a class property, if anyone knows a solution please contact me.
Upvotes: 2
Reputation: 11255
I am not sure of a way to do this in R, but you should be able to do it in powershell.
I am still learning powershell, but this at the very least gets all the properties and methods of an object:
$ol = New-Object -ComObject Outlook.Application
$new_item = $ol.CreateItem(0)
$new_item | Get-Member
TypeName: System.__ComObject#{...}
Name MemberType Definition
---- ---------- --------
HTMLBody Property string HTMLBody () {get} {set}
Subject Property string Subject () {get} {set}
Attachments Property Attachments Attachments() {get}
There are a lot more than this but I'm actually transcribing from my other computer which has Outlook installed. The Get-Member
works on more than just the application object so you can also see the members and properties accessible to the Outlook
object itself or other COMS.
It also appears that the VBA resources may be helpful:
https://learn.microsoft.com/en-us/office/vba/api/outlook.application.createitem
Name | Value | Description |
---|---|---|
olAppointmentItem | 1 | An AppointmentItem object. |
olContactItem | 2 | A ContactItem object. |
olDistributionListItem | 7 | A DistListItem object. |
olJournalItem | 4 | A JournalItem object. |
.... | ... | ... |
https://learn.microsoft.com/en-us/office/vba/api/outlook.mailitem
PROPERTIES
---------
Actions
AlternateRecipientAllowed
Application
Attachments
AutoForwarded
AutoResolvedWinner
BCC
BillingInformation
Body
BodyFormat
Categories
CC
...
Upvotes: 4
Reputation: 8270
If you have Outlook, Excel or Word installed then you can do the following ...
<All Libraries>
. Change the dropdown so it says Outlook, this will scope the object browser to just the Outlook type library.Enjoy!
Upvotes: 4