gaut
gaut

Reputation: 5958

Full list of methods for COM objects

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

Answers (3)

mzuba
mzuba

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

Cole
Cole

Reputation: 11255

I am not sure of a way to do this in R, but you should be able to do it in .

I am still learning , 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.
.... ... ...

And most importantly:

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

S Meaden
S Meaden

Reputation: 8270

If you have Outlook, Excel or Word installed then you can do the following ...

  1. Press F11 to get to a Visual Basic Application (VBA) Integrated Development Environment (IDE).
  2. On the menu bar go to Tools->References to prompt the References dialog box.
  3. On the References dialog box, in the Available References checkbox list, page down until you find Microsoft Outlook Library (or similar), once found then check the checkbox and then press OK to confirm selection and dismiss dialog. This adds a reference to the Outlook type library to the current project.
  4. With the Outlook type library referenced (see step (3)) one can now press F2 to show the Object Browser dialog box.
  5. In the Object Browser dialog box, select the top left dropdown list which will probably say <All Libraries> . Change the dropdown so it says Outlook, this will scope the object browser to just the Outlook type library.
  6. You can now browse all the objects in the Outlook type library. Select a class in the Classes pane on the left hand side and the class's methods will appear in the right hand side.

Enjoy!

Upvotes: 4

Related Questions