Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Microsoft Excel
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Macro programming === ==== VBA programming ==== {{Main|Visual Basic for Applications}} [[File:Functions in Excel.PNG|thumb|300px|Use of a user-defined function ''sq(x)'' in Microsoft Excel. The named variables ''x'' & ''y'' are identified in the ''Name Manager''. The function ''sq'' is introduced using the ''Visual Basic'' editor supplied with Excel.]] [[File:Subroutine in Excel.PNG|thumb|300px|Subroutine in Excel calculates the square of named column variable ''x'' read from the spreadsheet, and writes it into the named column variable ''y''.]] The Windows version of Excel supports programming through Microsoft's Visual Basic for Applications (VBA), which is a dialect of [[Visual Basic]]. Programming with VBA allows spreadsheet manipulation that is awkward or impossible with standard spreadsheet techniques. Programmers may write code directly using the Visual Basic Editor (VBE), which includes a window for writing code, debugging code, and code module organization environment. The user can implement numerical methods as well as automating tasks such as formatting or data organization in VBA<ref name="Press"> For example, by converting to Visual Basic the recipes in {{cite book|title=Numerical recipes: the art of scientific computing|author1=Press, William H. Press|author2=Teukolsky, Saul A.|author3=Vetterling, William T.|author4=Flannery, Brian P.|name-list-style=amp|year=2007|publisher=Cambridge University Press|isbn=978-0-521-88068-8|edition=3rd|url=https://books.google.com/books?id=1aAOdzK3FegC}} Code conversion to Basic from Fortran probably is easier than from C++, so the 2nd edition ({{ISBN|0521437210}}) may be easier to use, or the Basic code implementation of the first edition: {{cite book|title=Numerical recipes: routines and examples in BASIC|author=Sprott, Julien C.|year=1991|publisher=Cambridge University Press|isbn=978-0-521-40689-5|url=https://books.google.com/books?id=3-BfpBw7AqQC}} </ref> and guide the calculation using any desired intermediate results reported back to the spreadsheet. VBA was removed from Mac Excel 2008, as the developers did not believe that a timely release would allow porting the VBA engine natively to [[MacOS#Mac OS X|Mac OS X]]. VBA was restored in the next version, Mac Excel 2011,<ref>{{cite web|title=Excel|url=http://www.officeformachelp.com/excel/|url-status=dead|access-date=July 8, 2012|work=Office for Mac|publisher=OfficeforMacHelp.com|archive-date=June 19, 2012|archive-url=https://web.archive.org/web/20120619131821/http://www.officeformachelp.com/excel/}}</ref> although the build lacks support for [[ActiveX]] objects, impacting some high level developer tools.<ref>{{Cite web|title=Using Excel β PC or Mac? {{!}} Excel Lemon|url=https://www.excellemon.com/view/100-using-excel-pc-or-mac|archive-url=http://webarchive.loc.gov/all/20160921074527/https://www.excellemon.com/view/100-using-excel-pc-or-mac|url-status=dead|archive-date=September 21, 2016|website=excellemon.com|access-date=July 29, 2015}}</ref> A common and easy way to generate VBA code is by using the [[Macro (computer science)|Macro]] Recorder.<ref name="Walkenbach">However an increasing proportion of Excel functionality is not captured by the Macro Recorder leading to largely useless macros. Compatibility among multiple versions of Excel is also a downfall of this method. A macro recorder in Excel 2010 may not work in Excel 2003 or older. This is most common when changing colors and formatting of cells. {{cite book|author=Walkenbach, John|title=Excel 2007 VBA Programming for Dummies|publisher=Wiley|year=2007|isbn=978-0-470-04674-6|edition=Revised by Jan Karel Pieterse|page=79 ''ff''|chapter=Chapter 6: Using the Excel macro recorder|chapter-url=https://books.google.com/books?id=2IBbPiP3wOIC&pg=PA79}}</ref> The Macro Recorder records actions of the user and generates VBA code in the form of a macro. These actions can then be repeated automatically by running the macro. The macros can also be linked to different trigger types like keyboard shortcuts, a command button or a graphic. The actions in the macro can be executed from these trigger types or from the generic toolbar options. The VBA code of the macro can also be edited in the VBE. Certain features such as loop functions and screen prompt by their own properties, and some graphical display items, cannot be recorded but must be entered into the VBA module directly by the programmer. Advanced users can employ user prompts to create an interactive program, or react to events such as sheets being loaded or changed. Macro Recorded code may not be compatible with Excel versions. Some code that is used in Excel 2010 cannot be used in Excel 2003. Making a Macro that changes the cell colors and making changes to other aspects of cells may not be backward compatible. VBA code interacts with the spreadsheet through the Excel ''Object Model'',<ref name="Walkenbach2">{{cite book|title=cited work|author=Walkenbach, John|chapter-url=https://books.google.com/books?id=2IBbPiP3wOIC&pg=PA53|chapter=Chapter 4: Introducing the Excel object model|page=53 ''ff''|isbn=978-0-470-04674-6|date=February 2, 2007|publisher=John Wiley & Sons}}</ref> a vocabulary identifying spreadsheet objects, and a set of supplied functions or ''methods'' that enable reading and writing to the spreadsheet and interaction with its users (for example, through custom toolbars or ''command bars'' and ''message boxes''). User-created VBA [[subroutine]]s execute these actions and operate like macros generated using the macro recorder, but are more flexible and efficient. ==== History ==== From its first version Excel supported end-user programming of macros (automation of repetitive tasks) and user-defined functions (extension of Excel's built-in function library). In early versions of Excel, these programs were written in a macro language whose statements had formula syntax and resided in the cells of special-purpose macro sheets (stored with file extension .XLM in Windows.) XLM was the default macro language for Excel through Excel 4.0.<ref>{{cite web|title=The Spreadsheet Page for Excel Users and Developers|url=http://spreadsheetpage.com/index.php/site/tip/developer_faq_general_questions/|access-date=December 19, 2012|website=spreadsheetpage.com|publisher=J-Walk & Associates, Inc.|archive-date=January 21, 2013|archive-url=https://web.archive.org/web/20130121061001/http://spreadsheetpage.com/index.php/site/tip/developer_faq_general_questions/|url-status=live}}</ref> Beginning with version 5.0 Excel recorded macros in VBA by default but with version 5.0 XLM recording was still allowed as an option. After version 5.0 that option was discontinued. All versions of Excel, including Excel 2021, are capable of running an XLM macro, though Microsoft discourages their use.<ref>{{cite web|title=Working with Excel 4.0 macros|url=http://office.microsoft.com/en-us/excel-help/working-with-excel-4-0-macros-HA010336614.aspx|access-date=December 19, 2012|website=microsoft.com|publisher=Microsoft Office Support|archive-date=March 7, 2013|archive-url=https://web.archive.org/web/20130307194541/http://office.microsoft.com/en-us/excel-help/working-with-excel-4-0-macros-HA010336614.aspx|url-status=live}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)