I am trying to make an application in which i can send appointments to co-workers.
My code is as follows:
Public Sub SendAppointment()
Dim TempApp As Outlook.Application = New Outlook.Application()
'An AppointmentItem 'TempAppItem' object represent one appointment
Dim TempAppItem As Outlook.AppointmentItem = TempApp.CreateItem(Outlook.OlItemType.olAppointmentItem)
TempAppItem.Subject = Onderwerp.SelectedItem
TempAppItem.Body = Opmerking.Text
'Set Location
'TempAppItem.Location = "No Location"
'Set start and end date and times
TempAppItem.Start = Convert.ToDateTime(Btijd.SelectedItem)
TempAppItem.End = Convert.ToDateTime(Etijd.SelectedItem)
'Save to Calendar.
TempAppItem.RequiredAttendees("some#emailaddress.com")
TempAppItem.Send()
TempAppItem.Save()
TempApp = Nothing
TempAppItem = Nothing
End Sub
If I leave out:
TempAppItem.RequiredAttendees("some#emailaddress.com")
It creates the appointment in my own calendar. This proves the rest of the code works. But somehow no matter which argument i add to RequiredAttendees, I keep getting errors. Mostly saying "Too many arguments to 'Property RequiredAttendees As String'.
In my eyes the easiest would be if I can just use the users e-mailaddress as a value to a variable, but somehow it seems vb.net only uses the stored name of said contact, which doesn't seem to work :\
I can't find any explanation of how to properly set the RequiredAttendees property and I am starting to break my head over this. Can anyone help me out or at least push me in the right direction?
Related
I'd like to program Outlook to send an email in advance, and, if no reply is sent to the target email by x date, send another email.
I've attempted experimentation, dabbling into Excel VBAs, but haven't found a solution.
I'm really quite unsure of how to do this, though I do have programming experience.
I'd like to program Outlook to send an email in advance
That is a very straightforward task. A lot of samples are available over the internet, for example, sample code in VB.NET:
Private Sub CreateSendItem(OutlookApp As Outlook._Application)
Dim mail As Outlook.MailItem = Nothing
Dim mailRecipients As Outlook.Recipients = Nothing
Dim mailRecipient As Outlook.Recipient = Nothing
Try
mail = OutlookApp.CreateItem(Outlook.OlItemType.olMailItem)
mail.Subject = "A programatically generated e-mail"
mailRecipients = mail.Recipients
mailRecipient = mailRecipients.Add("Eugene Astafiev")
mailRecipient.Resolve()
If (mailRecipient.Resolved) Then
mail.Send()
Else
System.Windows.Forms.MessageBox.Show(
"There is no such record in your address book.")
End If
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message,
"An exception is occured in the code of add-in.")
Finally
If Not IsNothing(mailRecipient) Then Marshal.ReleaseComObject(mailRecipient)
If Not IsNothing(mailRecipients) Then Marshal.ReleaseComObject(mailRecipients)
If Not IsNothing(mail) Then Marshal.ReleaseComObject(mail)
End Try
End Sub
Read more about that in the following articles:
How To: Create and send an Outlook message programmatically
How To: Fill TO,CC and BCC fields in Outlook programmatically
How to create and show a new Outlook mail item programmatically: C#, VB.NET
if no reply is sent to the target email by x date, send another email.
You can set the following properties on the email:
MailItem.TaskDueDate which sets a Date value that represents the due date of the task for this MailItem.
MailItem.ReminderSet which sets a Boolean value that is True if a reminder has been set for this item.
MailItem.ReminderTime which sets a Date indicating the date and time at which the reminder should occur for the specified item.
In the Application.Reminder event handler you may check whether the mail item was replied or forwarded by reading a low-level property value. The property you would read would be PR_LAST_VERB_EXECUTED (0x10810003). Values are listed below:
EXCHIVERB_REPLYTOSENDER = 102
EXCHIVERB_REPLYTOALL = 103
EXCHIVERB_FORWARD = 104
Please remember that you can use the PropertyAccessor for that:
lastVerbExecuted = mailItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10810003")
Using Outlook 2016, I'm trying to retrieve the AutoResponse (https://learn.microsoft.com/en-us/office/vba/api/outlook.recipient.autoresponse) property for a recipient who is sending an out of the office message.
I get an empty string.
I check that the recipient is resolved through the .Resolved property and I see the auto message displayed if I pass the objMail.Display command. Am I missing something or is this a bug in Outlook?
Sub test()
Dim objMail As Outlook.MailItem
Dim objRecipient As Outlook.Recipient
Set objMail = Application.CreateItem(olMailItem)
Set objRecipient = objMail.Recipients.Add("alias#domain.com")
objRecipient.Resolve
MsgBox objRecipient.AutoResponse
End Sub
The related thread, as well as the answer it references, suggest alternatives (EWS and Redemption) that are not feasible due to access restrictions, and don't explore the potential root cause for .AutoResponse not behaving as described in the documentation.
Recipient.AutoResponse property is local to the message - it returns PR_RECIPIENT_AUTORESPONSE_PROP (0x5FFA001F) property from the message recipient table. It does not returns the OOF status.
The Recipient.AutoResponse property returns or sets a string representing the text of automatic response for a Recipient. So, you may try to set the property to any string and then check it later.
The Display method of the MailItem class displays a new Inspector object for the item. It doesn't show up an auto-response string.
Although I'm reasonable experienced VBA developer, I have not had the need to use class modules or collections but thought this may be my opportunity to extend my knowledge.
In an application I have a number of forms which all have the same functionality and I now need to increase that functionality. Towards that, I am trying to reorder a collection in a class module, but get an error 91 - object variable or with block not set. The collection is created when I assign events to controls. The original code I obtained from here (Many thanks mwolfe) VBA - getting name of the label in mousemove event
and has been adapted to Access. The assignments of events works well and all the events work providing I am only doing something with that control such as change a background color, change size or location on the form.
The problem comes when I want to reorder it in the collection - with a view to having an impact on location in the form. However I am unable to access the collection itself in the first place.
The below is my latest attempt and the error occurs in the collcount Get indicated by asterisks (right at the bottom of the code block). I am using Count as a test. Once I understand what I am doing wrong I should be able to manipulate it as required.
mLabelColl returns a correct count before leaving the LabelsToTrack function, but is then not found in any other function.
As you will see from the commented out debug statements, I have tried making mLabelColl Private and Dim in the top declaration, using 'Debug.Print mLabelColl.Count' in the mousedown event and trying to create a different class to store the list of labels.
I feel I am missing something pretty simple but I'm at a loss as to what - can someone please put me out of my misery
Option Compare Database
Option Explicit
'weMouseMove class module:
Private WithEvents mLbl As Access.Label
Public mLabelColl As Collection
'Dim LblList as clLabels
Function LabelsToTrack(ParamArray labels() As Variant)
Set mLabelColl = New Collection 'assign a pointer
Dim i As Integer
For i = LBound(labels) To UBound(labels)
'Set mLabelColl = New Collection events not assigned if set here
Dim LblToTrack As weMouseMove 'needs to be declared here - why?
Set LblToTrack = New weMouseMove 'assign a pointer
Dim lbl As Access.Label
Set lbl = labels(i)
LblToTrack.TrackLabel lbl
mLabelColl.Add LblToTrack 'add to mlabelcoll collection
'Set LblList as New clLabels
'LblList.addLabel lbl
Next i
Debug.Print mLabelColl.Count 'returns correct number
Debug.Print dsform.countcoll '1 - incorrect
End Function
Sub TrackLabel(lbl As Access.Label)
Set mLbl = lbl
End Sub
Private Sub mLbl_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
Dim tLbl As Access.Label
'Debug.Print LblList.Count 'Compile error - Expected function or variable (Despite Count being an option
'Debug.Print mLabelColl.Count 'error 91
'Debug.Print LblList.CountLbls 'error 91
Debug.Print collCount
End Sub
Property Get collCount() As Integer
*collCount = mLabelColl.Count* 'error 91
End Property
In order to have all the weMouseMove objects reference the same collection in their mLabelColl pointer, a single line can achieve it:
LblToTrack.TrackLabel lbl
mLabelColl.Add LblToTrack
Set LblToTrack.mLabelColl = mLabelColl ' <-- Add this line.
But please be aware that this leads to a circular reference between the collection and its contained objects, a problem that is known to be a source of memory leaks, but this should not be an important issue in this case.
I am trying to use a VBA script to pull info from the emails in Inbox into an excel spreadsheet:
'Subject
'To Address
'From Address
'CC Addresses
it fails for senders who have already left the organization and they're no longer in O365.
This is the code bit:
Function X400toSMTP(strAdr As String) As String
Dim olkRcp As Outlook.Recipient, olkUsr As Outlook.ExchangeUser
Set olkRcp = Session.CreateRecipient(strAdr)
If olkRcp.AddressEntry = Empty Then
X400toSMTP = strAdr
ElseIf olkRcp.AddressEntry.AddressEntryUserType = olExchangeUserAddressEntry Then
olkRcp.Resolve
Set olkUsr = olkRcp.AddressEntry.GetExchangeUser
X400toSMTP = olkUsr.PrimarySmtpAddress
End If
Set olkRcp = Nothing
Set olkUsr = Nothing
End Function
I ran the debug and it stops at AddressEntry : The attempted operation failed. An object could not be found
I'm trying to find a way to make the script leave the address field empty for those senders who cannot be found on O365 anymore and further process the rest of the items in the Inbox.
I have tried the below:
If IsNull(olkRcp.AddressEntry) Then
X400toSMTP = strAdr
but am still getting the same error for AddressEntry.
I am just a VBA noob so would very much appreciate your advice.
Many thanks!
Make sure the recipient is resolved before accessing the AddressEntry property - call olkRcp.Resolve.
Its 5th Question and apart of one I didn't get response from the experts....
Hope this time I will get the helping hand.
I want to do mailmerge in openoffice using Vb.net and I am totally new with openoffice.
I searched on net for some help to understand how to use openoffice with vb.net but all I get is half info.....So can you please help me and give me code for mailmerge in vb.net for openoffice.
Well i have list of workers in DB and there is this facility that if they want to mail to all or some of the workers then they can do it.I have completed this task using Microsoft Office now as a Add in we are providing the facility to perform the same task using Open Office.
What they have to do is just select the List of workers and click on a button and it will automate the mailmerge using the field of those workers data from DB. The Code of mine is as shown below
Public Sub OpenOfficeMail(ByVal StrFilter As String)
Dim oSM ''Root object for accessing OpenOffice from VB
Dim oDesk, oDoc As Object ''First objects from the API
Dim arg(-1) ''Ignore it for the moment !
''Instanciate OOo : this line is mandatory with VB for OOo API
oSM = CreateObject("com.sun.star.ServiceManager")
''Create the first and most important service
oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
''Create a new doc
oDoc = oDesk.loadComponentFromURL("private:factory/swriter", "_blank", 0, arg)
''Close the doc
oDoc.Close(True)
oDoc = Nothing
''Open an existing doc (pay attention to the syntax for first argument)
oDoc = oDesk.loadComponentFromURL("file:///C:\Users\Savan\Documents\1.odt", "_blank", 0, arg)
Dim t_OOo As Type
t_OOo = Type.GetTypeFromProgID("com.sun.star.ServiceManager")
Dim objServiceManager As New Object
objServiceManager = System.Activator.CreateInstance(t_OOo)
Dim oMailMerge As New Object
oMailMerge = t_OOo.InvokeMember("createInstance", Reflection.BindingFlags.InvokeMethod, Nothing, _
objServiceManager, New [Object]() {"com.sun.star.text.MailMerge"}) 'com.sun.star.text.MailMerge"})
oMailMerge.DocumentURL = "file:///C:\Users\Savan\Documents\1.odt"
oMailMerge.DataSourceName = CreateSource(StrFilter)''Function that will return the datasource name which will be a text file's path
oMailMerge.CommandType = 0
oMailMerge.Command = "file:///C:\Mail.txt"
oMailMerge.OutputType = 2
oMailMerge.execute(New [Object]() {})**---->I am getting Error here**
End Sub