Adding a Skype meeting invite through VBA - vba

I want to send a Skype meeting invite through excel macros. Is there a way to do it? Currently I can only create a normal meeting invite.
Dim olApp As Outlook.Application
Dim ol_Meeting As Outlook.AppointmentItem
Set olApp = New Outlook.Application
Set ol_Meeting = olApp.CreateItem(olAppointmentitem)
ol_Meeting.MeetingStatus = olMeeting
With ol_Meeting
.Display
.Attachments.Add ThisWorkbook.Path & "\" & ThisWorkbook.Name
End With

Assuming you're using Skype for Business and assume the macro is for you to use you can just create an outlook meeting invite and adding the automatic Skype link, right click on skype meeting link, edit hyperlink, copy it and add to your macro's email body.
This will populate your email with the link to access any Skype Meeting that you usually send. It works for me.

Related

forward emails from an outlook folder using vba

Here is the scenario:
My Outlook Inbox has a sub-folder called Notice. Every day, I will check and forward notices to my colleague if there is any automated notice in this folder. I would like to run a vba so that it will go into this folder, check inside, and if there is an email then forward, otherwise stop.
I would seek for your assistance on this scenario as I'm quite new to visual basic on outlook. Thank you very much.
Tony
You could create a macro rule when the folder received an email then forward this email.
Please refer to the below code:
Sub ForwardEmail(Item As Outlook.MailItem)
// Determine if it’s an email
If TypeName(Item) = "MailItem" Then
With Item.Forward
.Subject = ("ITS - ") & Item.Subject
.Recipients.Add "backup#email.com"
' You need to overwrite the Body or HTMLBody to get rid of the auto signature
.HTMLBody = Item.HTMLBody ' <-- Or use .Body for Plain Text
'.Display ' <-- For Debug
.Send ' <-- Put break here to Debug
End With
End If
End Sub
For more information, please refer to these links:
Otlook vba and rule to forward email message and change subject
VBA Copy sent mail to folder based on key words in subject

Outlook VBA - Move only emails from conversation that are still in inbox

I have adjusted a routine found on the internet in Outlook VBA that moves all emails from a conversation in inbox to a specific folder.
I move my emails by getting them like:
olItem As MailItem 'Put email from conversation in olItem
DestFolder As Outlook.Folder 'Destination folder where i want to send my email
olItem.Move DestFolder
Problem is: in this conversation I have sometimes older emails that have already been moved to the destination folder earlier: they appear in my inbox because of the way conversation mode works.
If I try to move it with olItem.Move DestFolder, the code fails as the email is already in DestFolder.
How to detect if an email is already in the destination folder and move it to ONLY if it's not there already
Thank you in advance for your help
A simple method that may suffice.
On Error Resume Next
olItem.Move DestFolder
' Turn error bypass off once the purpose for it has been served
On Error GoTo 0

Automatically connect to ms excel and check for unread emails using excel vba

I am doing a project based on excel-vba.
There are 2 users. User A and User B
User A has an excel workbook with a table. User B will be emailing a
document regularly,to user A's outlook account.
My requirement is by using a macro to give 2 options to user A.
option 1: manually check if there is unread email from a particular
user.
This is done by:
Opening outlook from within the excel workbook and then User A can manualy search through the outlook account.
I have successfully done this using the following code.
Sub Open_Outlook()
' This Macro Opens Microsoft Outlook
' Runs an executable program
Shell ("OUTLOOK")
End Sub
option 2: Automatically check if there is unread email from a particular user.
This is done by:
Create a Connection to Outlook.
Checking if there is any unread email.
Sub ExtractFirstUnreadEmailDetails()
Dim oOutlook As Object
Dim oOlns As Object
Dim oOlInb As Object
'~~> Get Outlook instance
Set oOutlook = GetObject(, "Outlook.Application")
Set oOlns = oOutlook.GetNamespace("MAPI")
Set oOlInb = oOlns.GetDefaultFolder(olFolderInbox)
'~~> Check if there are any actual unread emails
If oOlInb.Items.Restrict("[UnRead] = True").Count = 0 Then
MsgBox "NO Unread Email In Inbox"
Exit Sub
End If
End Sub
I am getting an error when i run the code for the second option.
Run time error 429: Active X component cant create object.
What does this mean?
How do i change the code to get rid of the error and to run it succesfully?
olFolderInbox is a Outlook only constant Either define it as a constant in VBA like this:
Const olFolderInbox = 6
Or simply replace it with 6 in the Set oOlInb line

Creating VBA macro to save email copy

I use Outlook (MS Exchange) and have an individual as well as two group inboxes (I'm working logged in with the individual profile through which I also have access to the group inboxes).
When I send an email, I chose either my individual or one of the two group email addresses in the From field. When the email is sent, I want a copy saved in the inbox of myIndividualMailbox, groupAMailbox, or groupBMailbox depending on which From email address I used.
Example: If I send an email From groupA#myCompany.com, I want a copy of the email saved in the inbox of the groupAMailbox (and not in my individual inbox).
I have understood that this is not possible by setting up a rule in Outlook but that it could be done with a VBA macro. I don't now how to write the VBA macro and don't know if this is a just a short script or more complicated. In fact I have never written a macro in Outlook so I don't even know how to begin. Can anyone show how to do this?
I started looking for a solution with this question: Outlook send-rule that filter on the 'From' field
I made this for you as far as I can tell, it works. You should put this in the Microsoft Outlook Objects - ThisOutlookSession Module.
Note that the myolApp_ItemSend event will never trigger unless you run enableEvents first. And you will need to make sure it is enabled every time you close an re-open Outlook. This will take some customization, but it should give you the general idea.
Option Explicit
Public WithEvents myolApp As Outlook.Application
Sub enableEvents()
Set myolApp = Outlook.Application
End Sub
Private Sub myolApp_ItemSend(ByVal item As Object, Cancel As Boolean)
Dim items As MailItem
Dim copyFolder As Outlook.Folder
Dim sentWith As String
'Identify sender address
If item.Sender Is Nothing Then
sentWith = item.SendUsingAccount.SmtpAddress
Else
sentWith = item.Sender.Address
End If
'Determin copy folder based on sendAddress
Select Case sentWith
Case "groupA#myCompany.com"
'get groupAMailbox's inbox
Set copyFolder = Application.GetNamespace("MAPI").folders("groupAMailbox").folders("Inbox")
Case "myE-mailAddress"
'get My inbox
Set copyFolder = Application.GetNamespace("MAPI").folders("myE-mailAddress").folders("Inbox")
End Select
'copy the Item
Dim copy As Object
Set copy = item.copy
'move copy to folder
copy.Move copyFolder
End Sub
EDIT: It looks like they've actually built the event functionality into the Application object for Outlook directly now, but it from testing you still have to do what I outlined above.
Outlook stores all sent items in default sent items folders. however you can apply a patch to save sent items in its own folder.
http://support.microsoft.com/kb/2181579

Spellcheck with VBA in Outlook 2007 in a specified language

I'm trying to spell check and send an outlook e-mail using the following macro:
Sub SpellIt()
Dim oMail As Outlook.MailItem
Dim oDoc As Word.Document
Set oMail = Application.ActiveInspector.CurrentItem
Set oDoc = Application.ActiveInspector.WordEditor
oMail.Save
oDoc.Content.LanguageID = wdGerman
oDoc.CheckSpelling
oMail.Save
oMail.Send
End Sub
I need to be able to set the language explicitly to German and I found it can be done using Content.LanguageID, but this does not include the subject line. How can I set the language for the subject line? Of course it would be even better to be able to set it for the whole document, but I cannot apply LanguageID to .Document
Any ideas?
Thanks,
Reto
The wordeditor is used in the body of the email (in certain conditions it will be null as well). So you would not be able to work with it that way.
oMail.Subject will get you the subject text I guess you can copy that into a new document and spellcheck that then copy it back? or insert it into you wordeditor in a know range and then check and set the subject back delete the orginal range etc.