I want to create a meeting invite only to book a room in outlook through Excel.
this is the code I am using,
Private Sub CommandButton2_Click()
Set myOutlook = CreateObject("Outlook.Application")
Set myApt = myOutlook.CreateItem(1)
myApt.Subject = "Training"
myApt.Start = Now
myApt.RequiredAttendees = "B 101-Training Room-24 <B101-TrainingRoom-24.IOC#cummins.com>"
myApt.End = Now + 30
myApt.MeetingStatus = olMeeting
myApt.send
MsgBox ("Meeting Invite Sent")
Set myOutlook = Nothing
Set myApt = Nothing
End Sub
this code doesnot create any meeting invite, but doesnot give error as well.
Can please tell what could be the missing thing?
Thanks.
I think you'd better use recipients, trying this
myApt.Recipients.Add("B 101-Training Room-24 <B101-TrainingRoom-24.IOC#cummins.com>")
The RequiredAttendees property only contains the display names for the required attendees. The attendee list should be set by using the Recipients collection.
Resources are usually added as BCC recipients:
set recip = myApt.RequiredAttendees("B 101-Training Room-24 <B101-TrainingRoom-24.IOC#cummins.com>")
recip.Type = 3 'olBCC
recip.Resolve
Do you see the meeting request in the Sent Items folder?
the code given adds all the fields except attendees. I want to have 'Invite attendees' option coded.
Set recip = myApt.RequiredAttendees("B 101-Training Room-24 <B101-TrainingRoom-24.IOC#cummins.com>")
is there any other way to add the invitees? FYI, I am using Outlook 2013.
Related
I am trying to send outlook mail using VBA . Every time I run my macro a pop-up comes to me of TITUS stating as select data risk classification. My question is if there any way I can bypass it or select it automatically and send an email.
I have the attempted code snippets to achieve it from multiple sources from internet below.
Sub test()
Dim AOMSOutlook As Object
Dim AOMailMsg As Object
Set AOMSOutlook = CreateObject("Outlook.Application")
Dim objUserProperty As Object
Set AOMailMsg = AOMSOutlook.CreateItem(0)
Set objUserProperty = AOMailMsg.UserProperties.Add("TITUSAutomatedClassification", 1)
objUserProperty.Value = "TLPropertyRoot=ABCDE;Classification=Internal;Registered to:My Companies;"
With AOMailMsg
.To = "v-fexue#outlook.com"
.Subject = "New Report"
.HTMLBody = "Hi"
.Save
.Send
End With
Set AOMailMsg = Nothing
Set objUserProperty = Nothing
Set AOMSOutlook = Nothing
Set lOMailMsg = Nothing
Set objUserProperty = Nothing
Set lOMSOutlook = Nothing
End Sub
Also please clear if objUserProperty.Value = "TLPropertyRoot=ABCDE;Classification=Internal;Registered to:My Companies; Registered to: (has to be actual company name)
Thanks in advance.
You may contact Titus developers for the actual format of the string that needs to be set to avoid any popups from their add-in in Outlook. Also you may check out the sent items for properties set by the add-in, use any low-level property explorer tool such as MFCMAPI or OutlookSpy for that.
I created vba code for sending out outlook invitation. it worked succesfuly. but i missed two parts and wanted to add it but don't know how. asking for your help
firstly i have the list of user's emails in excel and want to send the same invitation to all of them separately.
want to and (check names)
want to add code to check availability of recipients from suggested items.
asking for your help.
thanks
BTW: this is my code:
**Sub sendmeetinginvitation()
Dim O As Outlook.Application
Set O = New Outlook.Application
Dim OMT As Outlook.AppointmentItem
Set OMT = O.CreateItem(olAppointmentItem)
OMT.MeetingStatus = olMeeting
Dim mylist As String
mylist = OMT.Recipients.Add("........")
With OMT
.Subject = "test1"
.Start = #9/1/2020 12:00:00 PM#
.Duration = 60
.Display
.Send
End With
End Sub**
I'm making a VBA userform that replies to the active Outlook email with a template (different templates based on listbox choices). The problem right now is that when I "reply all" it is grabbing just the first and last name of the sender and recipients.
The senders are primarily outside the company, so I need it to grab and populate the "To" field with the actual email addresses. If it were only in-company the users would be in the company directory and it wouldn't be an issue. The closest I've come to finding this is the answer to How do you extract email addresses from the 'To' field in outlook?. I feel like the information I need is available there (only explicitly deals with grabbing info for recipients but I figure the same principle will apply to the sender), but I can't make sense of how to insert it into my code for the desired result.
Here's what I am starting from:
Private Sub CommandButton1_Click()
Dim origEmail As MailItem
Dim replyEmail As MailItem
Set origEmail = ActiveExplorer.Selection(1)
Set replyEmail = CreateItemFromTemplate("C:\Download Tool\Need Stat Code X.oft")
replyEmail.To = origEmail.ReplyAll.To
replyEmail.HTMLBody = replyEmail.HTMLBody & origEmail.Reply.HTMLBody
replyEmail.SentOnBehalfOfName = "emailaddress#mycompany.com"
replyEmail.Display
Set origEmail = Nothing
Set replyEmail = Nothing
End Sub
The emails are populating and I'm getting nearly all the info I want, but I haven't found a clear explanation of how to grab & insert the email addresses.
Thanks for your time and advice!
If you put a stop after "Set origEmail = ..." and set a watch on origEmail, you will see the properties of the email. Included is the Recipients collection. There are two (that I can see) types, SMTP and EX. For me, EX means internal. in each item in the recipients items is a property called address and another called addressentry. The addressentry part contains the address type.
deep breath
OK, so you need to be able to convert the EX addresses into internal addresses by parsing the part at the end, and you can just put the SMTP ones in as is, I think. Build a string of the addresses in the recipients address list and put it in the To and/or CC fields and you should be good. The To or CC part is the recipients (n).type property...
I think.
Gosh, I hope someone posts an easier way to do it :)
Thanks to both #hrothgar and #Tony for the responses. I learned about some new tools and techniques from each. Ultimately, based on the info found in your responses, I ended up searching for "vba get recipients string" and finding Get item.recipient with Outlook VBA .
The code now works and looks like this:
Private Sub CommandButton1_Click()
Dim origEmail As MailItem
Dim replyEmail As MailItem
'new stuff
Dim recip As Recipient
Dim allRecips As String
'end new stuff
Set origEmail = ActiveExplorer.Selection(1)
Set replyEmail = CreateItemFromTemplate("C:\Template Placel\My Template.oft")
'more new stuff
For Each recip In origEmail.Recipients
If (Len(allRecips) > 0) Then allRecips = allRecips & "; "
allRecips = allRecips & recip.Address
Next
'end more new stuff
replyEmail.To = origEmail.SenderEmailAddress & "; " & allRecips 'updated to find sender email and
replyEmail.HTMLBody = replyEmail.HTMLBody & origEmail.Reply.HTMLBody
replyEmail.SentOnBehalfOfName = "inbox#company.com"
replyEmail.Display
Set origEmail = Nothing
Set replyEmail = Nothing
End Sub
The internal contacts look a bit ugly in the "To" line, but I've tested and it gets the job done.
Thanks for the help!
I have this code to create an Outlook appointment from an Excel sheet. It's working fine. But I am using 2 e-mail accounts on Outlook and I don't know how to alternate the meeting host between these accounts. What is the property of AppointmentItem Object, that changes the meeting host?
PS: Isn't "Organizer", I have already tried.
#EDIT:
I was trying to use .SendUsingAccountas suggested by Macro Man, but, still not changing the sender.
My code:
Set oApp = CreateObject("Outlook.Application")
Set ItemAppoint = oApp.CreateItem(1)
ItemAppoint.MeetingStatus = olMeeting
'===============Accounts===============
Dim Var As Object
Set Var = ItemAppoint.session.accounts
'======================================
With ItemAppoint
.SendUsingAccount = Var(2) 'The account that I want to use is the index "2"
.Subject = "Sub"
.Body = "text"
.Display
End With
The .Organizer property is read-only, you're after the .SendUsingAccount property which is read/write
AppointmentItem.SendUsingAccount
More information on the MSDN pages: AppointmentItem.SendUsingAccount Property (Outlook)
The AppointmentItem.SendUsingAccount property allows to specify an Account object that represents the account under which the AppointmentItem is to be sent.
What is the property of AppointmentItem Object, that changes the meeting host?
The easiest way is to create an appointment item in the calendar folder which belongs to a particular account. What code do you use for creating appointment items?
The How To: Create a new Outlook Appointment item article explains all possible ways for creating appointment items in Outlook. Try to get the right folder and use the Add method of the Items class. For example:
items.Add(Outlook.OlItemType.olAppointmentItem)
The GetDefaultFolder method of the Store class returns a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument. This method is similar to the GetDefaultFolder method of the NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile.
This works Well.
Sub Test()
Dim oNamespace As Outlook.Namespace
Dim oCalendarFolder As Outlook.MAPIFolder
Dim oItems As Outlook.items
Dim strEntryID As String
Set oOutlook = CreateObject("Outlook.Application")
Set oNamespace = oOutlook.GetNamespace("MAPI")
For Each i In oNamespace.Folders
If i.Name = "yourEmailIDhere" Then
For Each j In i.Folders
If j.Name = "Calendar" Then
strEntryID = j.EntryID
End If
Next j
End If
Next i
Set oCalendarFolder = oNamespace.GetFolderFromID(strEntryID)
oItems = oCalendarFolder.items
oMeeting = oItems.Add(Outlook.OlItemType.olAppointmentItem)
oMeeting.Save
oMeeting.Display`
End sub`
I just arrived to this question when searching for a solution to the same problem: in my case the appointment was being created for a different account than desired, and the .SendUsingAccount property was of no help.
I managed to solve this by directly creating the appointment inside the folder I wanted:
Set OutlookApp = CreateObject("Outlook.Application")
Set AppointItem = OutlookApp.GetNamespace("MAPI").Folders("secondary#hostname.com").Folders("Calendar").Items.Add(Outlook.OlItemType.olAppointmentItem)
Now the appointment is created for the secondary#hostname.com account, and not for the default#hostname.com account.
I've an existing promotional mail with HTML formatting, colors, bullets etc. I would like to forward this mail to new set of recipients using VBA.
I've an existing mail with following Body:
Hi XXnameXX,
Some Picture are present & Lot of colored formatting.
Thanks for registering to our website. Your user id is XXuseridXX.
Thank you.
Here XXnameXX should be replaced with FirstName and XXuseridXX with userID
I am able to forward the selected mail from Outlook. But it's not forwarding it with all the images/formatting/bullets. On receiving end its showing a complete different mail with link and all.
Sub ForwardEmail()
Dim oApp As Outlook.Application
Dim objFolder As Outlook.MAPIFolder
Set oApp = New Outlook.Application
Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(olFolderInbox)
Dim oEmail As Outlook.MailItem
For Each objitem In Application.ActiveExplorer.Selection
If objFolder.DefaultItemType = olMailItem Then
If objitem.Class = olMail Then
Set myforward = objitem.Forward
Set objRecip = myforward.Recipients.Add("firstlastname#gmail.com")
myforward.HTMLBody = Replace(myforward.HTMLBody, "xxnamexx", "FirstName", 1, 1)
myforward.Send
End If
End If
Next
End Sub
First of all, don't use multiple dots in the single line of code. I'd recommend breaking the chain of calls and declare each property or method call on separate lines of code.
If objFolder.DefaultItemType = olMailItem Then
There is no need to check out the folder's property in the loop each time. I'd suggest moving that condition out of the loop.
objitem.BodyFormat = olFormatHTML
Why do you need to set up the BodyFormat property? Did have a chance to check the value before setting the property?
myforward.Body = Replace(myforward.Body, "xxnamexx", "FirstName", 1, 1)
The Body property is a string representing the clear-text body of the Outlook item. You need to use the HTMLBody property if you want to preserve the formatting. You can read more about all possible ways of working with item bodies in the Chapter 17: Working with Item Bodies.
Anyway, I don't see the code where you add images and other information to the message body.