Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / December 2006

Tip: Looking for answers? Try searching our database.

File Properties

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
briank - 18 Feb 2005 00:09 GMT
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 - 18 Feb 2005 00:57 GMT
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
Claud Balls - 18 Feb 2005 01:32 GMT
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.
guete227 - 13 Dec 2006 13:25 GMT
Would the code below pertain to only the workbook open?

Thanks.

>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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.