' Define global variables
Public userName As String
' Change the user as needed in this function
Function CurrentUser() As String
Dim fileName As String: fileName = ActiveWorkbook.path & "\config.txt"
Dim fcontent As String
Dim fileStream As Integer: fileStream = FreeFile
' File I/O stream
Open fileName For Input As #fileStream
fcontent = Input(LOF(fileStream), fileStream)
Close #fileStream
' userName is equal to contents of txt file
userName = fcontent
CurrentUser = userName
End Function
' Sets the username in config file
Sub SetCurrentUser()
Dim myInput As Variant: myInput = InputBox("Enter the current username")
Dim myFile As String: myFile = ActiveWorkbook.path & "\config.txt"
Dim fileStream As Integer: fileStream = FreeFile
' File I/O stream
Open myFile For Output As #fileStream
Print #fileStream, myInput
Close #fileStream
End Sub