Compare textbox.text with file name!

Zoticos

New Member
Joined
Jan 29, 2011
Messages
16
I’m having a problem in regards to comparing a string variable with a filename.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Here’s my sample.<o:p></o:p>
<o:p></o:p>
Textbox.text input is: “new york”<o:p></o:p>
My file name is: “C:\DATA\Location – New York.bmp”<o:p></o:p>
<o:p></o:p>
How can I read the filename as a string, and then compare the Textbox.text string with the filename?<o:p></o:p>
<o:p></o:p>
The compare needs to ignore the case and see if “new york” exist in the filename else exit sub.<o:p></o:p>
<o:p></o:p>
Thanks for any help!<o:p></o:p>
 
Last edited:

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi Zoticos,
the solution may be different depending of the version of Excel, but
try this code
Code:
Sub compareFileName()
Dim FileName As String
Dim MyFol As String
Dim f As String
    FileName = UCase(InputBox("Enter the file name"))
    
    Rem Change C:\data\ to your folder path
    MyFol = "C:\data\"
    f = Dir(MyFol, 7) 'look for files in D of type Read Only, Hidden and System
    Do While f <> ""
        f = UCase(f)
        If f Like "*" & FileName & "*" Then
            MsgBox ("hit on " & FileName)
        End If
        f = Dir
    Loop
End Sub
HTH
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,707
Members
452,939
Latest member
WCrawford

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