Sei sulla pagina 1di 3

Visual Basic for Applications

Visual Basic for Applications (VBA) is an implementa- compatible with Visual Basic .NET (VB.NET). VBA is
tion of Microsoft's event-driven programming language, proprietary to Microsoft and, apart from the COM interVisual Basic 6, and its associated integrated development face, is not an open standard.
environment (IDE).
Visual Basic for Applications enables building userdened functions (UDFs), automating processes and accessing Windows API and other low-level functionality
through dynamic-link libraries (DLLs). It supersedes
and expands on the abilities of earlier application-specic 2 Automation
macro programming languages such as Words WordBasic. It can be used to control many aspects of the host apInteraction with the host application uses OLE Automaplication, including manipulating user interface features,
tion. Typically, the host application provides a type lisuch as menus and toolbars, and working with custom
brary and application programming interface (API) docuser forms or dialog boxes.
umentation which document how VBA programs can inAs its name suggests, VBA is closely related to Visual Ba- teract with the application. This documentation can be
sic and uses the Visual Basic Runtime Library, but it can examined from inside the VBA development environnormally only run code within a host application rather ment using its Object Browser.
than as a standalone program. It can, however, be used to
Visual Basic for Applications programs which are written
control one application from another via OLE Automato use the OLE Automation interface of one application
tion. For example, it is used to automatically create a
cannot be used to automate a dierent application, even
Word report from Excel data, which are automatically
if that application hosts the Visual Basic runtime, because
collected by Excel from polled observation sensors. VBA
the OLE Automation interfaces will be dierent. For exhas the ability to use (but not create) (ActiveX/COM)
ample, a VBA program written to automate Microsoft
DLLs, and later versions add support for class modules.
Word cannot be used with a dierent word processor,
VBA is built into most Microsoft Oce applications, in- even if that word processor hosts VBA.
cluding Oce for Mac OS X (apart from version 2008)
Conversely, multiple applications can be automated from
and other Microsoft applications such as Microsoft Mapthe one host by creating Application objects within the
Point and Microsoft Visio, as well as being at least parVBA code. References to the dierent libraries must be
tially implemented in other applications such as ArcGIS,
created within the VBA client before any of the methAutoCAD, CATIA, Corel Draw and WordPerfect.
ods, objects, etc. become available to use in the application. This is achieved through what is referred to as
Early or Late Binding. These application objects create
the OLE link to the application when they are rst cre1 Design
ated. Commands to the dierent applications must be
done explicitly through these application objects in order
Code written in VBA is compiled[1] to a proprietary to work correctly.
intermediate language called P-code (packed code),
which the hosting applications (Access, Excel, Word, VBA code written in Microsoft Access can establish refOutlook, and PowerPoint) store as a separate stream in erences to the Excel, Word and Outlook libraries; this will
COM Structured Storage les (e.g., .docx or .xlsx) in- allow creating an application that runs a query in Access,
dependent of the document streams. The intermediate exports the results to Excel, formats the text, then writes
code is then executed[1] by a virtual machine (hosted by a mail merge document in Word that it automatically ethe hosting application). Despite its resemblance to many mails to each member of the original query through Outold BASIC dialects (particularly Microsoft BASIC, from look.
which it is indirectly derived), VBA is incompatible with VBA programs can be attached to a menu button, a
any of them except Visual Basic, where source-code of macro, a keyboard shortcut, or an OLE/COM event, such
VBA modules and classes can be directly imported, and as the opening of a document in the application. The lanwhich shares the same library and virtual machine. Com- guage provides a user interface in the form of UserForms,
patibility ends with Visual Basic version 6; VBA is in- which can host ActiveX controls for added functionality.
1

Security concerns

REFERENCES

so legacy 32-bit code ported to 64-bit VBA code that


depends on these common controls will not function.
The 32-bit version of Oce 2010 is unaected by this
issue.[11] VBA7 includes no 64-bit version of the common
controls, so it leaves developers with no means to migrate
VBA applications to 64-bits. Microsoft suggests contacting the software vendor for 64-bit versions of VBA controls.

Like any common programming language, VBA macros


can be created with malicious intent. Using VBA, most
of the security features lie in the hands of the user, not
the author. The VBA host application options are accessible to the user. The user who runs any document containing VBA macros can preset the software with user
preferences. End-users can protect themselves from attack by disabling macros from running in an application 4.1 Visual Studio Tools for Applications
or by granting permission for a document to run VBA
code only if they are sure the source of the document can Main article: Visual Studio Tools for Applications
be trusted.

Development

As of July 1, 2007, Microsoft no longer oers VBA distribution licenses to new customers. Microsoft intended
to add .NET-based languages to the current version of
VBA ever since the release of the .NET Framework,[2]
of which versions 1.0 and 1.1 included a scripting runtime technology named Script for the .NET Framework.[3]
Visual Studio .NET 2002 and 2003 SDK contained a
separate scripting IDE called Visual Studio for Applications (VSA) that supported VB.NET.[4][5][6] One of its
signicant features was that the interfaces to the technology were available via Active Scripting (VBScript and
JScript), allowing even .NET-unaware applications to be
scripted via .NET languages. However, VSA was deprecated in version 2.0 of the .NET Framework,[6] leaving no clear upgrade path for applications desiring Active Scripting support (although scripts can be created
in C#, VBScript, and other .NET languages, which can be
compiled and executed at run-time via libraries installed
as part of the standard .NET runtime).

5 See also
Visual Studio Tools for Oce
Microsoft Visual Studio
Microsoft FrontPage
OpenOce Basic

6 References
[1] ACC: Visual/Access Basic Is Both a Compiler and an Interpreter
[2] Visual Studio for Applications
[3] Introducing Visual Studio for Applications
[4] Script happens .NET: MSDN
[5] Microsoft Takes Wraps O VSA Development Technology

Support for VBA in the Mac OS X version of Microsoft [6] VSA scripting in .NET
Oce was dropped (for one version) with the release
of Microsoft Oce 2008 for Mac.[7][8] The ocial rea- [7] WWDC: Microsoft updates Universal status of Mac
apps. Macworld. 2006-08-07. Retrieved 2007-05-25.
son given was that VBA relied heavily on machine code
written for the PowerPC architecture, and that rewrit- [8] Oce 2008 without VBA
ing this code for dual PowerPC/Intel architectures would
have added another two years to the development of the [9] The Reports of VBAs Demise Have Been Greatly Exaggerated
suite. However, the Oce suite can be automated via
AppleScript to an extent. VBA was restored in Microsoft [10] Clarication on VBA Support
Oce for Mac 2011. Microsoft has clearly stated that
they have no plans to remove VBA from the Windows [11] Compatibility Between the 32-bit and 64-bit Versions of
Oce 2010
version of Oce.[9][10]
With Oce 2010, Microsoft has introduced VBA7 which
now contains a true pointer data type: LongPtr. This
new data type allows referencing 64-bit address space.
The 64-bit install of Oce 2010 does not support common controls of MSComCtl (TabStrip, Toolbar, StatusBar, ProgressBar, TreeView, ListViews, ImageList,
Slider, ImageComboBox) or MSComCt2 (Animation,
UpDown, MonthView, DateTimePicker, FlatScrollBar)

Text and image sources, contributors, and licenses

7.1

Text

Visual Basic for Applications Source: https://en.wikipedia.org/wiki/Visual_Basic_for_Applications?oldid=666833964 Contributors:


Koyaanis Qatsi, Heron, Tregoweth, Elliot100, Scanos, Raven in Orbit, Dysprosia, Furrykef, Itai, Bevo, Robbot, Chris 73, Lowellian,
Ashdurbat, Gilgamesh~enwiki, Enkrates, Uzume, Gadum, Gscshoyru, Dpen2000, RossPatterson, Rich Farmbrough, Thomas Willerich,
MattTM, Tslag, BjarteSorensen, Danakil, PhilHibbs, Cacophony, Jpgordon, Jlin, Shnout, L.Willms, AviGilChaitovsky, Garzo, Ae-a,
Tabletop, Mb1000, Palica, Elliotharmon, XP1, JanSuchy, FlaBot, Margosbot~enwiki, Ysangkok, Alvin-cs, Snailwalker, Miconian, Peterl, UkPaolo, Petiatil, Sikon, Shell Kinney, Igoeja, Xpclient, Jules.LT, NeilN, Tyomitch, AndrewWTaylor, SmackBot, Jonathan Karlsson, Marc Kupper, Bluebot, Thumperward, Adamralph, Wikibarista, DHN-bot~enwiki, Patleahy, JonHarder, Rrburke, Midnightcomm,
Philipwhiuk, MichaelBillington, Localzuk, Matt Whyndham, Mwtoews, DMacks, RNLion, SashatoBot, Kuru, RCX, Soumyasch, Michael
Bednarek, Spejic, TastyPoutine, Snakeyes060280, Hu12, Rubena, Jynus, Paul Foxworthy, Dondt1, RaviC, SkyWalker, FleetCommand,
Vessels42, Uildriks, Requestion, WeggeBot, Cydebot, A876, MC10, Drybittermelon, ST47, Torc2, Hervegirod, S Marshall, Marokwitz,
Magioladitis, Jatkins, Catgut, JaGa, Gwern, MartinBot, Uriel8, Wiki Raja, Century0, TottyBot, Joshua Issac, Cporch, Benrmac129, Mal
Browncoat, VolkovBot, Mcgimpsey, Classical geographer, Picassob, AlexDenney, Broadbot, Curb Safe Charmer, Billinghurst, AlleborgoBot, SieBot, Prakash Nadkarni, Mikescho2001, Jerryobject, Caddsoft, The Evil Spartan, Doctoruy, Train78, AlanUS, Anchor Link
Bot, Treekids, ImageRemovalBot, Missing Ace, 31stCenturyMatt, ClueBot, GorillaWarfare, Sga, JasonSharp, Alexbot, Oorang, Brews
ohare, Mikaey, Ooblagar, Ooblagar1, DumZiBoT, XLinkBot, Spitre, Knopfkind, Svgalbertian, Latha P Nair, Deineka, Addbot, Mortense,
Ghettoblaster, Tcncv, AkhtaBot, MrOllie, AnnaFrance, Jarble, Yobot, UltraMagnus, AnomieBOT, Materialscientist, Willem Souwer, Citation bot, Jimmy Bergmark, Xqbot, Flavonoid, Mcoupal, Mathonius, 123uvi, Rudimae, Genesispc, HamburgerRadio, OgreBot, Winterst,
DixonDBot, Aphranius, Seahorseruler, Mod mmg, EmausBot, Thnder, DominicConnor, Werieth, Glome4D, ClueBot NG, Sobhan niknam,
Open Excel, Jimnak, Helpful Pixie Bot, LiriK0s, GlynnCooke1, AvocatoBot, Mandiric, CitationCleanerBot, Hevey85, Codename Lisa,
Ga1, WorldWideJuan, Sunnycali, 2ndGenCoder, Ginsuloft, Mustha jm, Xdizzydust, Helios crucible and Anonymous: 226

7.2

Images

File:Commons-logo.svg Source: https://upload.wikimedia.org/wikipedia/en/4/4a/Commons-logo.svg License: ? Contributors: ? Original


artist: ?
File:Folder_Hexagonal_Icon.svg Source: https://upload.wikimedia.org/wikipedia/en/4/48/Folder_Hexagonal_Icon.svg License: Cc-bysa-3.0 Contributors: ? Original artist: ?
File:Microsoft_Office_2013_logo.svg Source: https://upload.wikimedia.org/wikipedia/commons/d/dd/Microsoft_Office_2013_logo.
svg License: Public domain Contributors: This le is derived from Microsoft Oce 2013.svg. Original artist: Microsoft Corporation
File:Question_book-new.svg Source: https://upload.wikimedia.org/wikipedia/en/9/99/Question_book-new.svg License: Cc-by-sa-3.0
Contributors:
Created from scratch in Adobe Illustrator. Based on Image:Question book.png created by User:Equazcion Original artist:
Tkgd2007
File:Symbol_book_class2.svg Source: https://upload.wikimedia.org/wikipedia/commons/8/89/Symbol_book_class2.svg License: CC
BY-SA 2.5 Contributors: Mad by Lokal_Prol by combining: Original artist: Lokal_Prol
File:Wikibooks-logo-en-noslogan.svg Source: https://upload.wikimedia.org/wikipedia/commons/d/df/Wikibooks-logo-en-noslogan.
svg License: CC BY-SA 3.0 Contributors: Own work Original artist: User:Bastique, User:Ramac et al.
File:Wikiversity-logo.svg Source: https://upload.wikimedia.org/wikipedia/commons/9/91/Wikiversity-logo.svg License: CC BY-SA 3.0
Contributors: Snorky (optimized and cleaned up by verdy_p) Original artist: Snorky (optimized and cleaned up by verdy_p)

7.3

Content license

Creative Commons Attribution-Share Alike 3.0

Potrebbero piacerti anche