ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   File Properties (https://www.excelbanter.com/excel-programming/323486-file-properties.html)

briank

File Properties
 
How can I reference the size of a spreadsheet (not necessarily the active
one) in an automated way? Ideally I want a cell in my active file to show
the size (i.e. 50k) and will change each time the active spreadsheet is
opened as the external file grows in size. Any thoughts?

Claud Balls

File Properties
 
This gives you names and sizes for all .xls files in the directory
containing the open workbook:
Sub dir_test()
Dim fs, f, s
Dim filespec As String
Dim count As Integer
count = 1
Set fs = CreateObject("Scripting.FileSystemObject")
filespec = Dir(ActiveWorkbook.Path & "\*.xls")
Do While filespec < ""
Set f = fs.GetFile(filespec)
s = f.Size
n = f.Name
Range("A" & count) = n
Range("B" & count) = s & " KB"
filespec = Dir
count = count + 1
Loop
End Sub

For one specific file:
Sub dir_test()
Dim fs, f

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile("H:\excel\Dir1.xls")

Range("A1") = f.Name
Range("B1") = f.Size & " KB"

End Sub

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Claud Balls

File Properties
 
I should have added, double click ThisWorkbook in the VB Editor and use:
Private Sub Workbook_Open()

to run code when a workbook is opened.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


All times are GMT +1. The time now is 10:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com