0% found this document useful (0 votes)
115 views2 pages

Vba - Create An Email in Outlook

The document provides several VBA macros for automating tasks in Microsoft Office applications. It includes scripts for creating an email in Outlook, deleting empty rows in Excel, removing empty text boxes in PowerPoint, and copying a contact from Outlook to Word. Each section includes a brief explanation of the functionality and usage of the respective macro.

Uploaded by

OusmaneKeita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views2 pages

Vba - Create An Email in Outlook

The document provides several VBA macros for automating tasks in Microsoft Office applications. It includes scripts for creating an email in Outlook, deleting empty rows in Excel, removing empty text boxes in PowerPoint, and copying a contact from Outlook to Word. Each section includes a brief explanation of the functionality and usage of the respective macro.

Uploaded by

OusmaneKeita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Create an email in Outlook

VBCopy
Sub MakeMessage()
Dim OutlookMessage As Outlook.MailItem
Set OutlookMessage = Application.CreateItem(olMailItem)
OutlookMessage.Subject = "Hello World!"
OutlookMessage.Display
Set OutlookMessage = Nothing
End Sub

Be aware that there are situations in which you might want to automate
email in Outlook; you can use templates as well.

Delete empty rows in an Excel worksheet

VBCopy
Sub DeleteEmptyRows()
SelectedRange = Selection.Rows.Count
ActiveCell.Offset(0, 0).Select
For i = 1 To SelectedRange
If ActiveCell.Value = "" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Next i
End Sub

Be aware that you can select a column of cells and run this macro to
delete all rows in the selected column that have a blank cell.

Delete empty text boxes in PowerPoint

VBCopy
Sub RemoveEmptyTextBoxes()
Dim SlideObj As Slide
Dim ShapeObj As Shape
Dim ShapeIndex As Integer
For Each SlideObj In ActivePresentation.Slides
For ShapeIndex = SlideObj.Shapes.Count To 1 Step -1
Set ShapeObj = SlideObj.Shapes(ShapeIndex)
If ShapeObj.Type = msoTextBox Then
If Trim(ShapeObj.TextFrame.TextRange.Text) = "" Then
ShapeObj.Delete
End If
End If
Next ShapeIndex
Next SlideObj
End Sub
Be aware that this code loops through all of the slides and deletes all text
boxes that don't have any text. The count variable decrements instead of
increments because each time the code deletes an object, it removes that
object from the collection, which reduces the count.

Copy a contact from Outlook to Word

VBCopy
Sub CopyCurrentContact()
Dim OutlookObj As Object
Dim InspectorObj As Object
Dim ItemObj As Object
Set OutlookObj = CreateObject("Outlook.Application")
Set InspectorObj = OutlookObj.ActiveInspector
Set ItemObj = InspectorObj.CurrentItem
Application.ActiveDocument.Range.InsertAfter (ItemObj.FullName & " from
" & ItemObj.CompanyName)
End Sub

Be aware that this code copies the currently open contact in Outlook into
the open Word document. This code only works if there is a contact
currently open for inspection in Outlook.

You might also like