Use Output of one function in another - Mr Excel Book

Sayth

Board Regular
Joined
Jun 4, 2010
Messages
212
Hi

I was trying to use two UDF's that I found as I read the Excel 2007 Mr Excel book. I am a little confused at how I use the output of one function in another.

This is the code largely adapted from the book, I think its chapter 4(not sure book at home).

Essentially the first function is supposed to place the fullpath and filename of the current workbook in a cell. I then want to use this full path name in another function to check the last save date. As the paths may change I want to use the returned result of the first function so that no matter where a user saves the file the last saved date can be checked.

Code:
Function MyFullName() As String
' Write the name of the full worksheet address in a cell
    MyFullName = Worksheets("ServiceDeliveryTemplate").Cells(A, 25).FullName
End Function
Function Lastsaved("MyFullName") As String
' retrieve full path from MyFullName Function and retrieve last save date.
Lastsaved = FileDateTime(MyFullName)
End Function
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Your first function makes no sense to me since a range does not have a fullname property. I think what you want is:
Code:
Function MyFullName() As String
    MyFullName = ThisWorkbook.FullName
End Function
Function Lastsaved() As String
' retrieve full path from MyFullName Function and retrieve last save date.
Lastsaved = FileDateTime(MyFullName())
End Function
 
Upvote 0
Dealing with your UDF's one at a time, the first one should be:

Code:
Function MyFullName() As String
'   Write the name of the full worksheet address in a cell
    MyFullName = ThisWorkbook.FullName
End Function

You can use it in a worksheet cell like this:

=MyFullName()

Your second one should be like this:

Code:
Function Lastsaved(FullName) As String
'   retrieve full path from MyFullName Function and retrieve last save date.
    Lastsaved = FileDateTime(FullName)
End Function

If A1 contains the full name, you can use it like this:

=Lastsaved(A1)
 
Upvote 0
Wow I totally misinterpreted UDF's. Now I understand, I create a function and then can reference the function via its name:). I was sort of combining UDF's and vba in my mess.

Is there a good article on how and where to save UDF's?
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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