Whenever you assign an object to an object variable, VB performs a process called binding. Objects can be early bound or late bound. It’s easy to tell the difference: If you declare a variable as Object, you are late binding. Early binding allows the compiler to perform other optimizations and allocate memory before an application executes, allowing the your code to run much faster. However, Late binding may be desirable In some instances.
'Early Binding Sub earlybinding() 'Create variable to hold new Excel App Dim xlApp As Excel.Application 'Assign Excel App to variable Set xlApp = New Excel.Application 'Add Workbook to xlApp & Make xlApp Visible xlApp.Workbooks.Add xlApp.Visible = True End Sub
'Late Binding Sub latebinding() 'Create variable to hold new object Dim xlApp As Object 'Assign Excel app to Object Set xlApp = CreateObject("Excel.Application") 'Add Workbook to xlApp & Make xlApp Visible xlApp.Workbooks.Add xlApp.Visible = True End Sub
VBA Coding Made Easy
Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!