Page 1 of 2
How to open Inbox, Calendar, Create Appointment did it with OLEHi RFobert
Posted: Sat Apr 06, 2019 2:15 pm
by rn@warner-it.com
Now I seem to have a problem with the Ole does anyone know another solution I am pasting the code I had before
I would greatly appreciate it if someone can help me get this working again any ideas ???
FUNCTION Calendar() AS VOID
// Add event handling code here
/* LOCAL objOL AS OBJECT
LOCAL objNS AS OBJECT
LOCAL objCalendar AS OBJECT
LOCAL objExplorer AS OBJECT
objOL := OleAutoObject{"Outlook.Application"}
objNS := objOL:GetNamespace("MAPI")
objCalendar := objNS:GetDefaultFolder(9)
objExplorer := objCalendar:GetExplorer
objExplorer:Activate()
*/
RETURN
FUNCTION Notes() AS VOID
// Add event handling code here
/*
LOCAL objOL AS OBJECT
LOCAL objNS AS OBJECT
LOCAL objContact AS OBJECT
LOCAL objExplorer AS OBJECT
objOL := OleAutoObject{"Outlook.Application"}
objNS := objOL:GetNamespace("MAPI")
objContact := objNS:GetDefaultFolder(12)
objExplorer := objContact:GetExplorer
objExplorer:Activate()
*/
RETURN
FUNCTION ContactClick() AS VOID
/*
LOCAL oApp AS Microsoft.Office.Interop.Outlook.Application
LOCAL objOL AS OBJECT
LOCAL objNS AS OBJECT
LOCAL objContact AS OBJECT
LOCAL objExplorer AS OBJECT
objOL := OleAutoObject{"Outlook.Application"}
objNS := objOL:GetNamespace("MAPI")
objContact := objNS:GetDefaultFolder(10)
objExplorer := objContact:GetExplorer
objExplorer:Activate()
*/
RETURN
This Code also does not work Hope to hear from someone !!! Thanks
Posted: Sat Apr 06, 2019 2:32 pm
by rn@warner-it.com
FUNCTION AddOutlookContact() AS VOID
LOCAL outApplication AS Microsoft.Office.Interop.Outlook.Application
*' Get the namespace and the logon.
LOCAL outNamSpace AS Microsoft.Office.Interop.Outlook.NameSpace
*' Create a new contact item.
LOCAL NewContact AS Microsoft.Office.Interop.Outlook.ContactItem
// Create an Outlook application.
// Get the namespace and the logon.
outApplication.GetNamespace("MAPI")
outApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olContactItem)
outNamspace.Logon("Outlook",NULL,TRUE,TRUE)
// Set some common properties.
NewContact:FirstName := _OutlookFnamecontact
NewContact:FullName := _OutlookSNamecontact
NewContact:Title := _OutlookFunction
NewContact:Birthday := Convert.ToDateTime("5/4/1969")
NewContact:CompanyName := M_Custname
NewContact:Department := "Development"
* NewContact.Body := "Sample"
*NewContact.FileAs := "Authorcode"
NewContact:Email1Address := _OutlookEmailcontact
NewContact:BusinessTelephoneNumber := _OutlookTel
NewContact:MobileTelephoneNumber := _OutlookMobile
NewContact:MailingAddress := _OutlookEmailcontact
NewContact:Subject := "Contact created from X#"
NewContact:JobTitle := _OutlookFunction
NewContact:Save()
NewContact:Display(TRUE)
*oApp := Nothing
*outNamSpace := Nothing
*NewContact := Nothing
RETURN
This Code also does not work Hope to hear from someone !!! Thanks
Posted: Sat Apr 06, 2019 3:27 pm
by Chris
Please explain what do you mean by "does not work". Do you get a compiler error, a runtime error? When? Does is just not save the contact? Something else fails?
How to open Inbox, Calendar, Create Appointment did it with OLE
Posted: Sat Apr 06, 2019 3:45 pm
by wriedmann
Hi Raymond,
why do you try with OleAutoObject? This is VO code and AFAIK does not works in X#.
You need to rewrite that code (in a much simpler manner) using the Microsoft.Office.Interop.Outlook library, like the one I have posted to your other message.
Wolfgang
P.S. it does not helps open up more threads for a similar issue. Open up one and wait until someone is able to help you.
How to open Inbox, Calendar, Create Appointment did it with OLE
Posted: Sat Apr 06, 2019 4:50 pm
by rn@warner-it.com
Hi Wolfgang,
Thanks for your advise will do in future I sent you a reply regarding the first code you sent me I get a compile error do you know the reason I am using exactly what you did only with more fields.
Thanks
Raymond
How to open Inbox, Calendar, Create Appointment did it with OLE
Posted: Sun Apr 07, 2019 1:42 pm
by George
In X#, you may use Microsoft.Office.Interop.Outlook.
Example for Outlook Contacts:
USING Microsoft.Office.Interop.Outlook
LOCAL outlook AS Microsoft.Office.Interop.Outlook.Application
LOCAL outlookNS AS Microsoft.Office.Interop.Outlook.NameSpace
outlook := Microsoft.Office.Interop.Outlook.Application{}
outlookNS := outlook:GetNamespace("MAPI")
LOCAL oContactFolder := SELF:outlookNS:PickFolder() AS MAPIFolder
IF oContactFolder == NULL
RETURN
ENDIF
FOREACH oFolderFound AS MAPIFolder IN oContactFolder:Folders
IF oFolderFound:DefaultItemType == Microsoft.Office.Interop.Outlook.OlItemType.olContactItem
//do something
ENDIF
NEXT
George
How to open Inbox, Calendar, Create Appointment did it with OLE
Posted: Sun Apr 07, 2019 8:25 pm
by robert
Raymond,
In .Net the recommended way to use com is not to use the oleautoobject class but to use a refernece to the interop library that is created when you add a com reference to your project, or to use a "primary interop assembly", a pre installed interop library that you will find in the first page of add reference dialog.
This approach works much better than the oleautoobject class.
If you look in the turorials in the documentation you should also find an example of how to automate excel that way.
Robert
How to open Inbox, Calendar, Create Appointment did it with OLEHi RFobert
Posted: Sun Apr 07, 2019 8:29 pm
by rn@warner-it.com
Hi Robert,
Thanks for the Info I will do so.
Thanks
Raymond
How to open Inbox, Calendar, Create Appointment did it with OLE
Posted: Sun Apr 07, 2019 8:30 pm
by rn@warner-it.com
Hi George,
I will try your code and let you know how I get on thanks for your help.
Regards,
Raymond
How to open Inbox, Calendar, Create Appointment did it with OLEHi RFobert
Posted: Mon Apr 08, 2019 5:58 pm
by ic2
Hello Raymond,
I am finalizing my program to read cells from an Excel spreadsheet. I hope to have it ready tomorrow and I'll publish it here so anyone wanting to do some Office automation should have a good starting point.
Dick