Professional Documents
Culture Documents
Yes, we can interact with the other Applications using VBA,i.e; with the MS Office Applications like Word,
PowerPoint,Outlook,etc… and other applications like Internet Explorer, SAS,etc…
to do this first we need to establish a connection with those applications, then we can able to access objects
of the other applications from VBA.
There are two ways to establish the Connection:Late binding and Early binding. In late binding, we will
create an Object in run time it will assign the necessary object. In early binding, we have to refer the
necessary object before we use it.
If you want to automate Other Microsoft Applications: You would declare the following variables at the top of
your procedure, you need to declare some object variables specific to the application being automated.
(In early binding, first we need to set a reference to the Other application’s object library. In the Visual Basic
Editor (VBE) => Select References… from the Tools menu => Select Other application’s object library)
Late Binding
Early binding – wee need to add the reference for required object.
For example if you want to interact with MS Word Application, you have to write the code as follows:
*Create a new module and Add the reference to Microsoft Word Object Library and then
Paste the following code into the module and run (Press F5) it to test it.
Sub sbWord_CreatingAndFormatingWordDoc()
Sub sbWord_CreatingAndFormatingWordDocLateBinding()
'Declarations
Dim oPPT As PowerPoint.Application
Dim oPPres As PowerPoint.Presentation
Dim oPSlide As PowerPoint.Slide
Dim sText As String
'Open PowerPoint
Set oPPT = New PowerPoint.Application
Set oPPres = oPPT.Presentations.Add
oPPT.Visible = True
'Add a Slide
Set oPSlide = oPPres.Slides.Add(1, ppLayoutTitleOnly)
oPSlide.Select
oPPT.Activate
'Release Objects
Set oPSlide = Nothing
Set oPPres = Nothing
Set oPPT = Nothing
'
End Sub
'Late Binding
Sub sbOutlook_SendAMail()
'Declaration
Dim oOApp As Object
Dim oMail As Object
'
Set oOApp = CreateObject("Outlook.Application")
Set oMail = oOApp.CreateItem(0)
'
On Error Resume Next
' Change the mail address and subject in the macro before you run it.
With oMail
.To = "userid@organization.com"
.CC = ""
.BCC = ""
.Subject = "Write Your Subject Here - Example mail - ANALYSISTABS.COM"
.Body = "Hi, This is example Body Text."
'
'.Attachments.Add ("C:\Temp\ExampleFile.xls") '=> To add any Attcahment
.Display '=> It will display the message
'.Send '=> It will send the mail
End With
On Error GoTo 0
'
Set oMail = Nothing
Set oOApp = Nothing
End Sub