Using OLE Automation in VB

The rest of the code

Now, let's add code to the save button:

Private Sub cmdSave_click()
If objDoc is nothing then
    
msgbox "Application not running"
else
    objdoc.Save
End if
End sub

We check whether the application is running or not. If it's running then we save the document otherwise we display a message telling the user that the application is not running.

Private Sub cmdClose-Click()
If objDoc is nothing then
    MsgBox"Application not running"
else
    objApp.Quit
    Set objDoc=Nothing
    Set objApp=Nothing
End if
End Sub

We check if the application is running or not. If it's running we close the application using the "Quit" method of the "Application" class. Note it's important to remove the application from the memory. The following lines remove the objects from the memory:

Set objDoc=Nothing
Set objApp=Nothing

Private Sub cmdExit_Click()

If objdoc is nothing then
    Unload me
Else
    MsgBox "Please close application first"
End If
End Sub

Unload the open form and use the "End" command to destroy instance of the application. That's it!

You might also like...

Comments

About the author

S.S. Ahmed United States

S.S. Ahmed is a senior IT Professional and works for a web and software development firm. Ahmed is a Microsoft Office SharePoint Server MVP. Ahmed specializes in creating database driven dynamic...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'” - Isaac Asimov