Checking for Authorization

wmtsub

Active Member
Joined
Jun 20, 2018
Messages
322
I would like a macro to read a txt file and compare the list of names on it against the system user. If the user appears on the list open the file and if not exit the file.
I am able to readt the system user and open a file but i am lost as to how to actually compare the data.

Can any one help?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I would like a macro to read a txt file and compare the list of names on it against the system user. If the user appears on the list open the file and if not exit the file.
I am able to readt the system user and open a file but i am lost as to how to actually compare the data.

Can any one help?

You could do something like this just substitute
Code:
Const strSearch = "Bill"
for
Code:
strSearch = Environ("USERNAME")
Code:
Sub SearchTextFile()
    Const strFileName = "C:\Users\Desktop\Text.txt"
    Const strSearch = "Bill"
    Dim strLine As String
    Dim f As Integer
    Dim lngLine As Long
    Dim blnFound As Boolean
    f = FreeFile
    Open strFileName For Input As [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=f"]#f[/URL] 
    Do While Not EOF(f)
        lngLine = lngLine + 1
        Line Input [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=f"]#f[/URL] , strLine
        If InStr(1, strLine, strSearch, vbBinaryCompare) > 0 Then
            'Open Workbook
            blnFound = True
            Exit Do
        End If
    Loop
    Close [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=f"]#f[/URL] 
    If Not blnFound Then
        MsgBox "String not found", vbInformation
    End If
End Sub
 
Last edited:
Upvote 0
Thank you. This but me on track for what I needed. Sorry to not have responded sooner, been very busy.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top