A function with no arguments
Several VBA functions such as rand() have no arguments. In the same way you can create custom functions that have no arguments. The following function will display the path and filename of the active workbook.
Function File()
File = ActiveWorkbook.FullName
End Function
Notice the function starts and ends with ‘Function’ rather than sub.
Enter =File() into a worksheet to see the result.
Click on fx and open the User Defined category to see your function listed here
The next function displays the username (as set in Tools | Options | General)
Function User()
User = Application.username
End Function |