Difference between CreateObject("Excel.Application") .Workbooks.Open and just Workbooks.Open Difference between CreateObject("Excel.Application") .Workbooks.Open and just Workbooks.Open vba vba

Difference between CreateObject("Excel.Application") .Workbooks.Open and just Workbooks.Open


Workbooks.Open uses the current MS Excel instance and CreateObject(“Excel.Application”) creates a new MS Excel instance. You can read up on CreateObject here.

Simply issuing a Workbooks.Open after creating a new instance will not ensure that the workbooks open in the new instance. You will have to bind with it. For example

Dim oXLApp As Object, wb As ObjectSet oXLApp = CreateObject("Excel.Application")'~~> Hide ExceloXLApp.Visible = False'~~> Open filesSet wb = oXLApp.Workbooks.Open("C:\Sample.xls")

Regarding your other question

Also, should I just use one instance of Excel created using CreateObject to open all Workbooks or do I need to create one instance for each workbook I have to process

You don't need several instances. You can work with one instance. For example

Dim oXLApp As Object, wb As ObjectSet oXLApp = CreateObject("Excel.Application")'~~> Hide ExceloXLApp.Visible = False'~~> Open filesSet wb = oXLApp.Workbooks.Open("C:\Sample1.xls")''~~> Do some Stuff'wb.Close (False)'~~> Open filesSet wb = oXLApp.Workbooks.Open("C:\Sample2.xls")''~~> Do some Stuff'wb.Close (False)''~~> And So on'


Late binding is slightly slower than early binding, but you may not even notice the difference. Yes, you can use just use one instance for all the workbooks. Note that this:

Dim xl As New Excel.Applicationxl.Workbooks.Open "z:\docs\test.xlsm"

Will not be visible unless you say:

xl.Visible = True

Be sure to close any instances in your error trap.