MS Outlook Interop CreateItem Task - syntax?

This forum is meant for questions and discussions about the X# language and tools
Post Reply
jonhn
Posts: 86
Joined: Thu Feb 01, 2018 8:04 am

MS Outlook Interop CreateItem Task - syntax?

Post by jonhn »

Hoping someone has a snippet they can post... I'm stuck on creating a new Outlook task - it was very easy in the VO/OLE I was using, and probably still is in X# with Interop but I've now gone slightly cross-eyed trying; so here I am again.

I'm declaring the Interop full class names in my code so as to avoid "USING" which was interfering with my other converted VO.Classes... It works for all the Word, Excel and other Outlook interop I've done, and this must be close...

Problem: I'm not sure if I've declared oTask as the right thing, and not sure how to finally instantiate it. Maybe I also need a Microsoft.Office.Interop.Outlook.TaskItemClass?

METHOD PBOutlook()
LOCAL oOutlook AS Microsoft.Office.Interop.Outlook.ApplicationClass
LOCAL oTask AS Microsoft.Office.Interop.Outlook.TaskItem

oOutLook := Microsoft.Office.Interop.Outlook.ApplicationClass{}

oTask:= oOutlook:CreateItem(oOutlook.OlItemType.olTaskItem) <---- this fails ( 'oOutlook' IS a variable but IS used like a type)

Here's one C# solution
task = (Outlook.TaskItem)OutlookApp.CreateItem(Outlook.OlItemType.olTaskItem);

If I look here: https://learn.microsoft.com/en-us/offic ... createitem, I can't get the OIItemType to identify as a TaskItem.

I've tried a lot of different ideas - I think it is Outlook.OlItemType.olTaskItem that I have wrong - if anyone has an idea that would be great!

Thank you.
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

MS Outlook Interop CreateItem Task - syntax?

Post by Chris »

Hi John,

I think that's what you're looking for:

oTask := oOutlook:CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olTaskItem)

the "OlItemType" is an enumeration, which a type containing many constants, it's not a member of the Application class that you were trying to use it at in your code snippet.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
jonhn
Posts: 86
Joined: Thu Feb 01, 2018 8:04 am

MS Outlook Interop CreateItem Task - syntax?

Post by jonhn »

Thank you Chris,
Yes, that is exactly the one I was looking for. Happy Sunday!
Post Reply