View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chris Putzig Chris Putzig is offline
external usenet poster
 
Posts: 5
Default help with create spreadsheet programmatically

Try this:
option explicit
dim f, fso, fSize, drives, drive, objXL, objWB
Dim objWS, myExcelFile, iRow, excelWorkbookExists, excelRunning, myWBname,
excelWorkbookOpen

myWBname = "myExcelFile.xls"
myExcelFile = "C:\" & myWBname
iRow = 2
excelWorkbookOpen = False
excelRunning = True
On Error Resume Next
Set objXL = GetObject(, "Excel.Application") 'Get object if Excel is open
If Err.Number < 0 Then
excelRunning = False
Set objXL = CreateObject("Excel.Application") 'Create object if Excel is
not open
End If
On Error GoTo 0
If excelRunning Then
On Error Resume Next
Set objWB = objXL.Workbooks(myWBname) 'Set if target Workbook open
End If
On Error GoTo 0
If IsEmpty(objWB) Then
On Error Resume Next
Set objWB = objXL.Workbooks.Open(myExcelFile) 'Open if WorkBook not open
Else
excelWorkbookOpen = True
End If
On Error GoTo 0
If IsEmpty(objWB) Then ' Create sheet if needed
excelWorkbookExists = False
Set objWB = objXL.Workbooks.Add
Set objWS = objWB.Sheets.Add
objWS.Name = "Folders"
objWS.Cells(1,1) = "Folder Name"
objWS.Cells(1,2) = "Folder Size"
objWS.Cells(1,3) = "Date-Time"
Else 'find next open cell if sheet exists
excelWorkbookExists = True
Set objWS = objWB.Sheets("Folders")
Do While objWS.Cells(iRow, 1) < ""
iRow = iRow + 1
Loop
End If
Err.Clear
On Error GoTo 0
f = "C:\WINNT"
' "set" a reference to the filesystem object
Set fso = createobject("Scripting.FileSystemObject")

' now get the bytes of folder f and hang onto it
fSize = fso.GetFolder(f).Size

' echo it out
wscript.echo "Folder size:", fSize

Msgbox "The size of the folder " &f & " is: " & fSize & " bytes"

objWS.Cells(iRow, 1) = f
objWS.Cells(iRow, 2) = fSize
objWS.Cells(iRow, 3) = Now
If excelWorkbookExists Then
objWB.Save
Else
objWB.SaveAs myExcelFile
End If
If Not excelWorkbookOpen Then objWB.Close
If Not excelRunning Then objXL.Quit


"Divyesh Raithatha" wrote in message
...
Hello I have a script that gets the folder size and
outputs it into a message box. Instead of outputting this
into a message box, I would like to output it into a
running excel spreadsheet with date and time. Any ideas?

option explicit
dim f, fso, size, drives, drive

f = "C:\WINNT"

' "set" a reference to the filesystem object
set fso = createobject("Scripting.FileSystemObject")

' now get the bytes of folder f and hang onto it
size = fso.GetFolder(f).Size

' echo it out
wscript.echo "Folder size:", size

Msgbox "The size of the folder " &f & " is: " &size & "
bytes"