![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Posts: 97
|
My excel app requires a refresh of all data every minute or so. I have that part done. What I would like to do is write to a log file every time a refresh is done, reporting errors and what not. Problem is, I don't want these log files getting to large in size. I have the idea in my head, how I want to do it. I just can't seem to get the code down. Here's an idea of what I'm trying to do:
I would have 1 log file called mach.log. That would be the primary file being written to all the time. I would then have in code to check the size of that file before writing to it, if it's over 250000 bytes, then rename mach.log to "mach" &Date& ".log". And then start with a clean mach.log all over again. Something like this (this is pretty ruff at this point): set f = mach.log 'you get the point.... if f.size > 250000 then f.rename ("mach." & Date & ".log") else f.write(....) end if Hopefully you follow...? The problem? Is there an actual method .rename? I can't find anything that would do that... [ This Message was edited by: charlie79 on 2002-03-26 08:23 ] |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Posts: 97
|
Someone... SVP.....
|
|
|
|
|
|
#3 |
|
New Member
Join Date: Mar 2002
Location: Trumbull Services
Posts: 2
|
Hey Charlie. Have you tried the FileSystemObject? Check the code below from the excel help file. You can get the size, in bytes, of the file in question.
Good luck! Size Property Description For files, returns the size, in bytes, of the specified file. For folders, returns the size, in bytes, of all files and subfolders contained in the folder. Syntax object.Size The object is always a File or Folder object. Remarks The following code illustrates the use of the Size property with a Folder object: Sub ShowFolderSize(filespec) Dim fs, f, s Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFolder(filespec) s = UCase(f.Name) & " uses " & f.size & " bytes." MsgBox s, 0, "Folder Size Info" End Sub |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Posts: 97
|
Yes, I realize that part of it. I believe that code came directly from excel help and I've been there already. What I'm asking is if there is a way to rename the file if it is over 250000 bytes... Thanks for the idea though. Anyone else... Please!
|
|
|
|
|
|
#5 |
|
New Member
Join Date: Mar 2002
Location: Trumbull Services
Posts: 2
|
You should be able to say ...
If F.Size > X Then F.CopyFile FromFileName, ToFileName F.DeleteFile FromFileName Set a = f.CreateTextFile(FromFileName, True) End If This should give you a new (empty) logfile if the size of the file grows bigger than X. |
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Feb 2002
Posts: 97
|
That looks more like what I was looking for! Great, thanks a bunch!!
|
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Feb 2002
Posts: 97
|
Tested 'er out, works great cbass!!!
Thanks again... |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|