MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.
Private Sub Workbook_Open() Const ForReading = 1 Const ForAppending = 8 Dim objFSO As Object Dim objFil As Object Dim strFilePath As String Dim strLast As String Dim strNum As String Dim strContents As String Dim arrLines strFilePath = ThisWorkbook.Path & "\log.txt" Set objFSO = CreateObject("Scripting.FileSystemObject") On Error Resume Next Set objFil = objFSO.getfile(strFilePath) On Error GoTo 0 If objFil Is Nothing Then Set objFil = objFSO.createTextFile(strFilePath, ForWriting) objFil.writeline "1," & Environ("username") & "," & Now() Else Set objFil = objFSO.OpenTextFile(strFilePath, ForReading) strContents = objFil.ReadAll objFil.Close Set objFil = objFSO.OpenTextFile(strFilePath, ForAppending) arrLines = Split(strContents, vbCrLf) strLast = arrLines(UBound(arrLines) - 1) strNum = Val(Left(strLast, InStr(strLast, ",") - 1)) + 1 objFil.writeline strNum & "," & Environ("username") & "," & Now() End If objFil.Close Sheets("EXPENSE FORM").Range("N2").Value = strNum End Sub
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.