Well I have a decent solution that requires only one line of code per function call that does everything at once:
Code:
Sub Main()
Dim log As Object
Set log = OpenLog("C:\Test.txt")
If WriteLog(log, "Hello there!", True) = True Then Exit Sub
If CloseLog(log) = True Then Exit Sub
End Sub
Function OpenLog(strFilePath As String) As TextStream
Dim objFSO As New Scripting.FileSystemObject
Dim objLogFile As TextStream
Const ForAppending As Integer = 8
If objFSO.FileExists(strFilePath) Then
Set objLogFile = objFSO.OpenTextFile(strFilePath, ForAppending, True)
Else
Set objLogFile = objFSO.CreateTextFile(strFilePath, False)
End If
objLogFile.WriteLine "Log Opened: " & _
Format(Now, "mm/dd/yyyy") & " " & _
Format(Now, "hh:mm:ss AM/PM")
Set OpenLog = objLogFile
End Function
Function WriteLog(objLogFile As TextStream, strMessage As String, blnExit As Boolean) As Boolean
objLogFile.WriteLine strMessage & Chr(13)
If blnExit = True Then
WriteLog = True
Else
WriteLog = False
End If
End Function
Function CloseLog(objLogFile As TextStream) As Boolean
objLogFile.WriteLine "Log Closed: " & _
Format(Now, "mm/dd/yyyy") & " " & _
Format(Now, "hh:mm:ss AM/PM")
objLogFile.Close
Set objLogFile = Nothing
CloseLog = True
End Function
Thanks for all your help,
Sanctos