Okay so I have a new project. I created a help file VIA a text file ( I know I could use .chm or .hlp but I would rather use a .txt file ) now once a user clicks a button I want it to open that text file and search for a string of text and locate and show that section of text. My code is pretty messy and nasty so far but here. Im using this withing a userform. Please help.
I can't get this to work for the life of me. Someone please help. Thank you very much.
Code:
Private Sub ClickLabel1()
Dim filepath As String
Dim srtxt As String
filepath = "C:\Program Files\Excel\wtithelp.txt"
srtxt = "Topic 1"
Function fnFindText(filepath, srtxt)
strFileRes = fnFileExistence(filepath)
If strFileRes = "File Exists" Then
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filepath, ForReading, True)
Do While f.AtEndOfStream <> True
A = f.readline
'MsgBox a
If InStr(A, srtxt) <> 0 Then
boolStFnd = "True"
fnFindText = "Text found"
Exit Do
End If
Loop
If boolStFnd <> "True" Then
fnFindText = "Text not found"
End If
f.Close
Else
fnFindText = "File does not exists"
End If
End Function
I can't get this to work for the life of me. Someone please help. Thank you very much.