Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default help with create spreadsheet programmatically

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"
  #2   Report Post  
Posted to microsoft.public.excel.programming
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"



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HOW-TO: programmatically create SAS length statement William W. Viergever Excel Discussion (Misc queries) 1 January 13th 09 09:47 AM
Programmatically Add Reference` keepitcool Excel Programming 1 September 16th 03 05:30 PM
Programmatically Add Reference` Jean-Paul Viel Excel Programming 0 September 16th 03 02:23 PM
Can i set a reference programmatically? Tom Ogilvy Excel Programming 1 August 19th 03 04:24 PM
How to create picklists programmatically Harald Staff[_4_] Excel Programming 0 July 16th 03 09:59 AM


All times are GMT +1. The time now is 01:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"