View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Todd huttenstine Todd huttenstine is offline
external usenet poster
 
Posts: 260
Default Retrieving value from function

Below is a function that I got from KeepITKool.

The variable DirSize returns the total size of a specified
directory. The value of this variable is what I am
interested in returning. This function is in a seperate
module than where the code starts executing. What I want
to do is after the function finishes running and then the
code execution moves back into the first module, I want to
access the value of variable DirSize. How do I do this?



Public Function DirSize&(Optional sDir$, Optional sMask$
= "*.*")
Dim n&, sFile$
If sDir = vbNullString Then
sDir = VBA.CurDir$
End If
If VBA.Right$(sDir, 1) < Application.PathSeparator Then
sDir = sDir & Application.PathSeparator
End If

sFile = VBA.Dir$(sDir & sMask)
While sFile < vbNullString
n = n + VBA.FileLen(sDir & sFile)
sFile = VBA.Dir$()
Wend

DirSize = n

End Function