Talk:Visual Basic for Applications

From Wikipedia, the free encyclopedia

This article is within the scope of Computing WikiProject, an attempt to build a comprehensive and detailed guide to computers and computing. If you would like to participate, you can edit the article attached to this page, or visit the project page, where you can join the project and/or contribute to the discussion.
??? This article has not yet received a rating on the quality scale.
??? This article has not yet received an rating on the importance scale.

Contents

[edit] Please add

1. Discussion of how VBA, WSH, VB script all are similar and may share technology 2. Links to MS documentation on VBA (found on the MS Office developer page)

[edit] "Hundreds of applications"?

Office, Autocad, Intellicad... anything else? Mathcad and Visual Basic Script.

It looks like the reference to "Hundreds of applications" was removed some time ago. Btw - Visual Basic Script is an independent implementation of Visual Basic based syntax. It is not an application of VBA. Ralphy 09:45, 7 February 2006 (UTC)

[edit] Examples

User:Snakeyes060280 - why have you added 'DAO' library qualifications to the object names? Ralphy 16:32, 6 February 2006 (UTC)

[edit] Where is there a VBA language reference/specificaation?

I've been looking for an online reference to the VBA language, but have not been able to find anything about the language itself (as opposed to APIs for the various MS Office applications for instance).

Does anyone know where there is a VBA language specification? Erland Lewin 13:40, 15 March 2006 (UTC)

Try Here: http://msdn2.microsoft.com/en-us/isv/aa905357.aspx Oorang (talk) 22:45, 13 February 2008 (UTC)

[edit] Edit by 84.146.195.216

I started to remove errors in the edit by 84.146.195.216 on 22:09, 19 September 2006 [1] however I find almost everything in that edit is incorrect or misleading. Furthermore there is a much better discussion of the strengths and weakness of the Visual Basic language in the visual basic article. This is why I am rolling back to the edit before 84.146.195.216. There some of the problems with the edit I am removing:

VBA's entities can be roughly divided in to classes: Firstly, there are the usual elements forming a programming language: data types, variables, control- and loop-struktures. This part of VBA is intended not to be application specific and is used to express the program logic. Secondly, there is an API which allows VBA to interact with it's host application. This API is specific to the relative application.

The APIs described in this section are not part of the VBA language or runtime environment. They are OLE Automation APIs which can be called from VBA and other languages with COM support. This also simplification of VBA also ignores that VBA is more than a language, it is also an integrated development environment. All these parts of VBA are discussed in the Description section of the article.

VBA itself is an [[Interpreter (computing)|interpreted] language. Precompilation is only used for syntax-check and to build tables for the variables used. Therefore VBA cannot be used to create standalone executables. Interpretation also causes the high memory requirement and low execution speed compaired with compiled programs.

VBA is an interpreted language and it can't be used to create standalone executables, I am keeping this in the article. However, this section does not say what VBA is being compared to. I some cases VBA may be slower or require more memory than alternatives and in some cases the opposite is the case. Since VBA runs in process with the application it is automating VBA programs often run faster that out of process compiled programs. Many compiled programs also load large libraries used for COM support.

VBA is a descentant of Microsoft's Visual Basic and therefor has it's roots in the Beginner's All-purpose Symbolic Instruction Code. Like BASIC, VBA also targets end users, being unexperienced programmers or complete beginners in the field of programming. It aims to support many of the simple language constructs, that were used in early BASIC Languages. Since BASIC since the early days lacked standardisation, there were lots of different dialects over the time, so VBA usually supports several syntactial constructs for the same programming goal. This can lead to a confusing variety of syntax and logical breaches: Examples:

  • ) The keyword "Let" might be neglected when asigning predefined types. But when asigning user defined types another keyword, "Set", is mandatory.
  • ) Variables are implicitely defined, except a directive, "Option Explicit", is used at the beginning of a script.
  • ) Subroutines are cathegorized in "functions" (returning a value) and sub (not returning a value). Functions must be called using brackets arount their arguments. Eigher their returnvalue as to be assigned to a variable, or the keyword "call" must be used, while subs must not be used in an assignment. When calling subs, the keyword "call" is optional but determines, whether brackets have to be used or not. All of the above syntax variants exist with named or unnamed arguments, additionally all arguments might be optional, taking on a default value proposed by the programmer when no value is assigned in the call.

I am keeping some of this section since it is correct that VBA is a decedent of BASIC and design decisions in the language favor inexperienced programmers. VBA's attempt to hide the difference between value and reference types does lead to confusion and the ability to omit variable deceleration can lead to errors however these are common in many languages. The description of how Let and Set are used is incorrect. Let is used with value types and set with object references, not with predefined types and user defined types. The use of a keyword to specify whether a subroutine returns a value or not may actually lead to less confusion than other approaches such as using a void return type. The discussion about the Call keyword and the use of practices is completely incorrect in VBA 6.

Despite of its close resemplance to many old BASIC dialects, VBA is not compatible to any of them, except Microsoft Visual Basic: Here the source-code of VBA Modules can be directly imported. Compatibility ends with Visual Basic Verison 6, VBA ist not compatible to VB.NET. Although being along with MS-Office a widespread product, VBA is proprietary to Microsoft and forms no Open standard.

This I am keeping except for the removal of the reference to Microsoft Office as VBA's use within those products has no relationship to whether it is an open standard or not.

VBA still supports flow control using the keyword "goto" (often called Spaghetti code in the jargon) but is mostly designed for Procedural programming.

VBA supports procedural and object orientated programming, event driven programming and possible other paradigms. Goto can lead to Spaghetti code but they are not the same thing. I will link to article on VBA where there is a more in depth discussion of the strengths and weakness of the Visual Basic language

VBA can depict classes and thereby supports data encapsulation, but lacks support for the other [[Object-oriented programming|object-orientated] techniques, like class-attributes and inheritance. So most of the [[Design pattern (computer science)|design patterns] of object orientated programming cannot be realized and VBA cannot be called an object orientated language.

VBA supports class-attributes and interface inheritance and can be used to implement many popular design patterns. I don't know if it can implement most design because there is no list of all design patterens.

Interaction with the host application is usually well documented. One of the most important elements is the "application" object, which integrates almost all automatizeable functions. The API is usually specific to an application and incompatible to all others. So VBA-code written for MS-Office API can not be used in [[OpenOffice]} using the StarBasic-API for example, although StarBasic and VBA are very resemblant considering the language. Most software products (Autodesk AutoCAD / Microsoft Office / Adobe Illustrator) provide an API in form of an 'Object Model' to the Visual Basic Environment allowing the user to create anything from small macros that perform repetitive tasks to extensive programs that add functionality to the host program.

The article on OLE Automation provides a good discussion on how VBA can interact with the host application's APIs. I wall callout more clearly at the start of the article.

Macros can be attached to a menu, button a keyboard shortcut or an event in the application like the opening of the document. Also user-defined functions for excel-worksheets can be provided.

Security Issues VBA is designed without any security features in the language, like for example the sandbox that java appletts run in. Any function of the application or even of the whole operating system, that is accessible to the user running an document containing VBA-macros can be (ab)used by a VBA-makro. Even persons of low programming skills can thus easily write a so called macro virus causing damage to almost unlimited extent. To ensure basic safety for the system and to protect data from espionage or destruction, several measures are necessary:

  • ) An external Virus-Scanner with macro-blocking function must be used, to close the security holes left open by VBA design.
  • ) Macro-capable Documents from unknown or unreliable sources must not be opened.
  • ) Macro-capable applications must not be run as system administrator.
  • ) The signature features provided with newer VBA-Versions should be used to verify the origin of a macro-containing document.

I am leaving this section in with a cleanup tag since it contains a number of errors and typos.

Patleahy 15:59, 20 September 2006 (UTC)

[edit] Second Person Adress

In the section addressing security, this article uses second person address. I know generally, this type of address has no place in formal writing, but I'm unfamiliar with the etiquette of this type of article. Should someone reword the offending passage?--Amanaplanacanalpanama 23:06, 7 November 2006 (UTC)

Yes, you should reword it. --Patleahy 15:47, 9 November 2006 (UTC)

[edit] Interpreted vs. Compiled

The article says VBA is a interpreted language. The compiled language article lists VBA and the interpreted language article does not. Which is it?Jcdietz03 15:14, 7 May 2007 (UTC)

It's definitely interpreted. If it's compiled then things like CurrentDB or Selection would never work. What happens when VBA codes are run is that the program will run the code from the top (which happens sometimes when badly written vba codes would work in some situations and not in others depends on what programs are open and which files are open). The biggest giveaway is that you don't need to compile first to run VBA macros. :) Leigao84 16:17, 10 May 2007 (UTC)

It is compiled to a p-code machine. It hasn't been interpreted since Access Basic/Word Basic. It takes a text version in BASIC, and compiles it to a seperate copy, which it runs in the VB Virtual Machine, MSVBVM60.DLL, and before that MSVBVM50.DLL. Corruption of the compiled copy is common problem: google the Access coding news groups. Depending on your environment, you may have Compile On Demand or Compile On Save. CurrentDB is a function that does a lookup, including refreshing a collection. I don't know what Selection does, but I do know that you can do File Open in compiled languages: basic input and output is not a mark of an interpreted language.
VBA, which is/was a microsoft product for compilation into a host product, includes an on-demand compiler option. That may look a lot like an interpreter when called from the VBA immediate window, but it's not the same thing.
Obviously, this article needs a lot of work, but it was a labour of love from some one: I'm not going to trash it today. 150.101.166.15 07:23, 31 August 2007 (UTC)
for what it's worth, the MS article about Access 97 currently used as a reference (December 2007), http://support.microsoft.com/kb/109382, is no longer completely accurate: text is not interpreted as you type. Instead, text is syntax checked by an independent syntax checker in the IDE as you type. The syntax checker shares code with the visual studio code completion feature, not the VBA compiler. 218.214.18.240 (talk) 06:05, 29 December 2007 (UTC)

[edit] Advert?

This article was tagged advert today. I must say I don't really agree. Anyone in for some discussion? Classical geographer 22:03, 14 August 2007 (UTC)

Concur. I've removed it until the editor can explain his concerns. Kuru talk 23:25, 14 August 2007 (UTC)

[edit] UserForms aren't "part of the language" are they?

Aren't UserForms an OLE/ActiveX object that can be used with VBA?150.101.166.15 (talk) 04:25, 13 December 2007 (UTC)

[edit] Fair use rationale for Image:VBA logo.jpg

Image:VBA logo.jpg is being used on this article. I notice the image page specifies that the image is being used under fair use but there is no explanation or rationale as to why its use in this Wikipedia article constitutes fair use. In addition to the boilerplate fair use template, you must also write out on the image description page a specific explanation or rationale for why using this image in each article is consistent with fair use.

Please go to the image description page and edit it to include a fair use rationale. Using one of the templates at Wikipedia:Fair use rationale guideline is an easy way to insure that your image is in compliance with Wikipedia policy, but remember that you must complete the template. Do not simply insert a blank template on an image page.

If there is other fair use media, consider checking that you have specified the fair use rationale on the other images used on this page. Note that any fair use images lacking such an explanation can be deleted one week after being tagged, as described on criteria for speedy deletion. If you have any questions please ask them at the Media copyright questions page. Thank you.

BetacommandBot (talk) 06:56, 21 January 2008 (UTC)

[edit] Pointers

There is a section here that says "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 add support for class modules."

VBA has an AddressOf operator which returns a pointer to the function for use with API calls.Oorang (talk) 01:19, 28 January 2008 (UTC)

Additional Note: You can get string, object, and variable pointers via the VarPtr, StrPtr, and ObjPtr functions built into the VBA library.[1]Oorang (talk) 19:29, 12 May 2008 (UTC)

[edit] Infobox

Add info box. A second pair of eyes would not be amiss Oorang (talk) 01:46, 28 January 2008 (UTC)

[edit] a virtual machine hosted inside the container application

Arguably false, but perhaps just a simplification. It uses the VB6 dll,s if they are in memory, or an equivilant set of runtime dlls if the vb6 dlls are not in memory. That is, the virtual machine is hosted by Windows, and the program always runs the same way a non-native mode vb6 program runs. Id change it if I could think of a way to write it that wasnt even more confusing and misleading, but I cant, because of course vba is hosted inside the container application. —Preceding unsigned comment added by 218.214.18.240 (talk) 07:59, 9 February 2008 (UTC)

[edit] Fair use rationale for Image:Vba office 2003.PNG

Image:Vba office 2003.PNG is being used on this article. I notice the image page specifies that the image is being used under fair use but there is no explanation or rationale as to why its use in this Wikipedia article constitutes fair use. In addition to the boilerplate fair use template, you must also write out on the image description page a specific explanation or rationale for why using this image in each article is consistent with fair use.

Please go to the image description page and edit it to include a fair use rationale. Using one of the templates at Wikipedia:Fair use rationale guideline is an easy way to insure that your image is in compliance with Wikipedia policy, but remember that you must complete the template. Do not simply insert a blank template on an image page.

If there is other fair use media, consider checking that you have specified the fair use rationale on the other images used on this page. Note that any fair use images lacking such an explanation can be deleted one week after being tagged, as described on criteria for speedy deletion. If you have any questions please ask them at the Media copyright questions page. Thank you.

BetacommandBot (talk) 02:33, 12 February 2008 (UTC)