To create an instance of excel using VB.Net, we can write the following piece of code:
Imports System
Imports Microsoft.Office.Interop.Excel
Imports Word = Microsoft.Office.Interop.Word
Module Program
'declaration statements
Dim oXL As Microsoft.Office.Interop.Excel.Application
Dim oWB As Workbook
Dim oSheet As Worksheet
Dim oWord As Word.Application
Dim oDoc As Word.Document
Sub Main(args As String())
'Console.WriteLine("Hello World!")
oXL = CreateObject("Excel.Application")
oXL.Visible = True
oXL.DisplayAlerts = True
Console.WriteLine("Type returned by CreateObject: {0}", oXL.GetType())
oWB = oXL.Workbooks.Add
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add
Console.ReadLine()
oXL.Quit() 'Not getting the warning
oWord.Quit(False) 'Not getting the warning
End Sub
End Module
Till here all is good. However I also came across the following statement in the MSDN Link:
Use the Application property to return the Application object.
I checked and found that the APPLICATION property is a member of _Application
interface, the usage criteria of which as per this link is mentioned below.
Use this primary interface only when the method you want to use shares the same name as an event of the COM object
However this statement is not clear to me. So can someone please explain (if possible with an example) when should I use the Application
property of the _Application
interface to return an Application object? Also is the object returned by the Application
property any different from the one being returned by createObject in the statement oXL = CreateObject("Excel.Application")
?