Discussion Locked

Excel 2000 Hyperlink - Folder Sizes

0 helpful
16 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I'm setting up a worksheet that will monitor the folder sizes on our servers. Is there a way to hyperlink the folder size into an Excel spreadsheet or would there be an easier way to do this?

16 replies

by seagull data services

Have a look at the FileSystemObject in the VB Scripting Library. It should have a method to get foldersizes that you could include in a custom function.

by beerman97

Yikes, sounds kind of scary to me. There's nothing easier than doing some visual basic programming?

by beerman97

I'm not very familiar with VBA at all. If someone could write some code for me it would be greatly appreciated.

by dklippert

Here's a cobble from the VB help file. It shows the size of a selected file, but you can add code to search for other folders and present the data as you wish. The important part is indicated at the end of the code.
(This app sometimes throws in extra spaces, so take that into account)

Sub FolderList()
'
' Macro to show folder size.

Dim x, fs
Dim I As Integer
Dim y As Integer
Dim Folder, MyName, TotalFiles, Response, PrintResponse, AgainResponse

On Error Resume Next

Folder:
' Prompt the user for the folder to list.
x = InputBox("What folder do you want to list?" & Chr$(13) & Chr$(13) _
& "For example: C:\My Documents")

If x = "" Or x = " " Then
Response = MsgBox("Either you did not type a folder name correctly" _
& Chr$(13) & "or you clicked Cancel. Do you want to quit?" _
& Chr$(13) & Chr$(13) & _
"If you want to type a folder name, click No." & Chr$(13) & _
"If you want to quit, click Yes.", vbYesNo)

If Response = "6" Then
End
Else
GoTo Folder
End If
Else

' Test if folder exists.
Set Folder = CreateObject("Scripting.filesystemobject")
If Folder.folderexists(x) = "True" Then
Else
MsgBox "The folder does not exist. Please try again."
GoTo Folder
End If
End If
' SEE BELOW FOR SIZE CODE
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(x)
s = UCase(f.Name) & " uses " & f.Size & " bytes."
MsgBox s, 0, "Folder Size Info"

End:
End Sub

by beerman97

That's what I want but I also want to be able to insert result of that script into an Excel spreadsheet and have it update automatically when I run the macro or open the spreadsheet again. Any other ideas? I've got about 800 or so folders and about 1000 other files that I want to be able to total up automatically.

by chris hirst

What you propose to do will take a lot of VBA code to acomplish. Unless you intend to hard code every folder name on the drive into a worksheet (not good from an admin point of view, simple for programmer)The code will have to scan the drive(s) to get all folder names and attributes, then calculate folder and file sizes, Display folder names etc into the worksheet which will need to be created 'on the fly' Not a trivial task by any means. If you have to follow the Excel route, The best way would be to write VB (not VBA) code to create the sheet rather than have a sheet try to create the data. On the other hand if you look into this from a different angle you may find third party reporting tools that will do exactly what you require. Check up on Crystal Reports and/or Seagate's other reporting tools there are more out there wiating to be discovered, You don't always have to re-invent the wheel (experience talking)

This discussion is closed to new replies.