Use Of VB Application

 22nd Jan 2007 03:06:49 AM

 use of VB Application
use of VB Application
  # 22nd Jan 2007 03:25:00 AM


Visual Basic for Applications (VBA) is an implementation of Microsoft's Visual Basic,an event driven programming language and associated development environment which is built into most Microsoft Office applications (including Apple Mac OS versions),some other Microsoft applications such as Microsoft MapPoint and Microsoft Visio - a former independent application which was acquired by Microsoft; as well as being at least partially implemented in some other applications such as AutoCAD,WordPerfect and ESRI ArcGIS. It supersedes and expands on the capabilities of earlier application-specific macro programming languages such as Word's WordBasic,and can be used to control almost all aspects of the host application,including manipulating user interface features such as menus and toolbars and working with custom user forms or dialog boxes. VBA can also be used to create import and export filters for various file formats,such as ODF.

VBA itself is an interpreted language. As its name suggests,VBA is closely related to Visual Basic,but can normally only run code from within a host application rather than as a standalone application. It can however be used to control one application from another using OLE Automation (for example,automatically creating a Word report from Excel data).

VBA is functionally rich and extremely flexible but it does have some important limitations,including limited support for function pointers which are used as callback functions in the Windows API. It has the ability to use (but not create) (ActiveX/COM) DLLs and later versions



A common use of VBA is to add functionality that may be missing from the standard user interface. This macro provides a shortcut for entering the current date in Word:

Sub EnterCurrentDate()
' EnterCurrentDate Macro
' Macro recorded 15/03/2005 by UserName
Selection.InsertDateTime DateTimeFormat:="d-MMM-yy",InsertAsField:=False,_
End Sub

VBA is useful for automating database tasks such as traversing a table:

Sub LoopTableExample
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM tblMain")
Do Until rs.EOF
MsgBox rs!FieldName
Set rs = Nothing
Set db = Nothing
End Sub

VBA can be used to create a user defined function (UDF) for use in a Microsoft Excel workbook:

Public Function BusinessDayPrior(dt As Date) As Date
Select Case Weekday(dt,vbMonday)
Case 1
BusinessDayPrior = dt - 3      'Monday becomes Friday
Case 7
BusinessDayPrior = dt - 2      'Sunday becomes Friday
Case Else
BusinessDayPrior = dt - 1      'All other days become previous day
End Select
End Function
Copyright © 2015 VisualBuilder. All rights reserved