application object - vba functions

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi

I have been under impression that to call any vba function (please see the list below), I need to use this syntax

application.FunctionName

but I just noticed that I can call these function without Application.

Code:
Sub myfunctions()
MsgBox Chr(66)
MsgBox Now()
MsgBox Int(55.12345)
End Sub

Is it safe to say I can call all the functions below without Application.FunctionName? Just the function name as above? and to call WorksheetFunction then I need to do

Application.Worksheetfunction.FunctionName

Thank you very much.

https://www.techonthenet.com/excel/formulas/index_vba.php
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You can call worksheetfunctions (most, but not all) using either Application.function or Application.WorksheetFunction.function. They mostly behave the same except in how they deal with errors. The Application.function version return an error value, whereas the worksheetfunction.function versions cause a run time error.

The functions you listed above are native VBA functions rather than Excel.
 
Upvote 0
Thank you very much for your help. Just to clarify, can I say that

1) to call VBA native functions - I just need to use function name (the list in the link above)

2) to call WorkSheetFunction functions I need to use this syntax Application.Worksheetfunction.FunctionName

With that I will be safe. But I do not have to use Application.FunctionName to call any WorkSHeetFunction
instead I will use Application.WorkSheetFunction.FunctionName

Thanks once again
 
Upvote 0
1. Correct.
2. No you can use either syntax in almost all cases. It just depends what you want to happen when there is an error.
 
Upvote 0
Thank you once again for the help. I see that I can call Sum for example using

Application.sum

Or

Worksheetfunction.sum

but if that is the case, when I say Application.sum, from Object oriented point of view, Application is a class/object and sum is a method/function in that class/object. So when I use Object browser, I should find an object called Application and inside it I should see Sum() but that is not the case. Why is that?

For WorksheetFunction, the object browser will list all its functions no problem. Thank you so much

Code:
Sub myfoo()
    Dim x As Integer
    Dim y As Integer
    x = Application.WorksheetFunction.Sum(Range("a1:a10"))
    y = Application.Sum(Range("a1:a10"))
    MsgBox x
    MsgBox y
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,640
Members
448,974
Latest member
DumbFinanceBro

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top