ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Logging things.. (https://www.excelbanter.com/excel-programming/294561-logging-things.html)

Foss

Logging things..
 
Mornin' all!

I'm using something like this to log progress and errors
etc to a text file:

LogFile = CleanFolderPath("MY FOLDER PATH HERE") & MyDoc
& " Run Log.txt"
Open LogFile For Output As #1
Print #1, "Report page " & MyRepName & " saved to " &
MySaveLocation

etc etc.

There is the potential for two files to be open at once,
how can I use the first available number instead of the #1?

Cheers,
Foss

Rob van Gelder[_4_]

Logging things..
 
FreeFile is what retrieves the number you're after:

Sub test()
intFreeFile1 As Integer, intFreeFile2 As Integer

LogFile = CleanFolderPath("MY FOLDER PATH HERE") & MyDoc & " Run
Log.txt"
intFreeFile1 = FreeFile
Open LogFile For Output As #intFreeFile1
intFreeFile2 = FreeFile
Open LogFile2 For Output As #intFreeFile2
Print #intFreeFile1, "Report page " & MyRepName & " saved to " &
MySaveLocation
Print #intFreeFile2, "Something else"
End Sub

I assume here that you're closing the file afterward.
In this example it would be:
Close #intFreeFile2
Close #intFreeFile1


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Foss" wrote in message
...
Mornin' all!

I'm using something like this to log progress and errors
etc to a text file:

LogFile = CleanFolderPath("MY FOLDER PATH HERE") & MyDoc
& " Run Log.txt"
Open LogFile For Output As #1
Print #1, "Report page " & MyRepName & " saved to " &
MySaveLocation

etc etc.

There is the potential for two files to be open at once,
how can I use the first available number instead of the #1?

Cheers,
Foss




Foss

Logging things..
 
Thanks very much! That's just what I'm after!

After a few problems earlier on, I'm now closing my files!!

Cheers,
Foss

-----Original Message-----
FreeFile is what retrieves the number you're after:

Sub test()
intFreeFile1 As Integer, intFreeFile2 As Integer

LogFile = CleanFolderPath("MY FOLDER PATH HERE") &

MyDoc & " Run
Log.txt"
intFreeFile1 = FreeFile
Open LogFile For Output As #intFreeFile1
intFreeFile2 = FreeFile
Open LogFile2 For Output As #intFreeFile2
Print #intFreeFile1, "Report page " & MyRepName & "

saved to " &
MySaveLocation
Print #intFreeFile2, "Something else"
End Sub

I assume here that you're closing the file afterward.
In this example it would be:
Close #intFreeFile2
Close #intFreeFile1


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Foss" wrote in

message
...
Mornin' all!

I'm using something like this to log progress and errors
etc to a text file:

LogFile = CleanFolderPath("MY FOLDER PATH HERE") & MyDoc
& " Run Log.txt"
Open LogFile For Output As #1
Print #1, "Report page " & MyRepName & " saved to " &
MySaveLocation

etc etc.

There is the potential for two files to be open at once,
how can I use the first available number instead of the

#1?

Cheers,
Foss



.



All times are GMT +1. The time now is 02:03 AM.

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