VBA - Application Object

The application object allows you to control the host program. Tools and features inside the application are now accessible in your vb code.

These features also allow the some mathematical functions to be accessed.


Code:
Sub MakeActive()

Application.Windows("Book1.xlsx").Activate

End Sub


Sub MakeNew()

'create new workbook
Set xl = CreateObject("Excel.Sheet")
xl.Application.Workbooks.Open "new.xlsx"

End Sub


Sub hide()


MsgBox Application.Height
MsgBox Application.ActivePrinter
MsgBox Application.DecimalSeparator

Application.ScreenUpdating = False
' do something complex
Application.ScreenUpdating = True

End Sub

Accessing Excel Functions through VBA

Functions that you can use in cells are not directly available though VBA, though through the Application object you can access them. For example there is no rounddown function in VBA. But you can access the excel rounddown function for use in your VBA code.




Code:
Sub test1()

Dim x As Double

x = 12.4342

MsgBox Application.WorksheetFunction.RoundDown(x, 2)

End Sub





Related Sections

Python - Learn the python from the basics up. This fast track example code course will get you creating powerful python programs in no time.



Must Read Articles


VBA and Microsoft Excel - Getting the most out of excel with VBA programming
VBA and Microsoft Word - Getting the most out of word with VBA programming
Application Object - Using the applications features in your code.
Installing VBA and First Program - What do you need to start using visual basic application VBA.