Page 1 of 4
Introduction
Because VBA is used by many applications beyond Excel, the Excel worksheet functions are not part of the VBA language itself. However, you can call worksheet functions directly through the Application object or through the Application.WorksheetFunctions class. The difference between using or omitting the WorksheetFunctions reference is how errors are handled. This is discussed below.
http://www.cpearson.com/excel/callingworksheetfunctionsinvba.aspx
11/3/2011
Page 2 of 4
http://www.cpearson.com/excel/callingworksheetfunctionsinvba.aspx
11/3/2011
Page 3 of 4
If there is the possibility that you will have a procedure with the same name as an ATP function, you can prefix the function name with the library name to ensure you are calling the correct function. Compare Excel For example, tables Dim Res As Variant Res = [atpvbaen.xls].MRound(123.456, 0.5) Debug.Print Res
Note that the square brackets ([ ]) are required in the library name because the name contains a period. The name of the add-in is an abbreviation of Analysis Tool Pack VBA ENglish.. If you are using a language other than English, the last two characters of the add-in name will be the language name abbreviation. This page last updated: 20-October-2007 Created by Chip Pearson at Pearson Software Consulting, LLC Email: chip@cpearson.com Before emailing me, please read this page. http://www.cpearson.com/excel/callingworksheetfunctionsinvba.aspx Copyright 1997 - 2011, Charles H. Pearson Submit bug information or errors on the Bug And Error Report Page.
http://www.cpearson.com/excel/callingworksheetfunctionsinvba.aspx
11/3/2011
Page 4 of 4
http://www.cpearson.com/excel/callingworksheetfunctionsinvba.aspx
11/3/2011