In the specified folder search for a file with name part of user input

sbnktn

New Member
Joined
Jul 22, 2013
Messages
24
Hi,

I have this code to search in the specified folder for the file whose name starts with the user input. I havejust placed msg boxes to check if he code works till there. but I am not able t reach the second msg box. could anybody help me.

code placed here
Code:
Sub CopytoSum()

Dim fname As String
Dim fpath As String
Dim sumfile As String
Dim xlfile As Workbook
fninput = InputBox("Please enter the name of the company", Title:="ENTER COMPANY NAME", Default:="Enter Name here")
fninput = fname
MsgBox "over"
If fninput = "ENTER COMPANY NAME" Or invinput = vbNullString Then
    Exit Sub
Else
    fpath = "L:\EXIM\SOFTEX FORMS\Summary\"
    sumfile = Dir(fpath & "fname*.*")
    MsgBox "secondover"
    Do While sumfile <> " "
    Set xlfile = Workbooks.Open(Filename:=fpath & sumfile)
    
    MsgBox "thirdover"
    sumfile = Dir()
    Loop

End If
End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Remove the space in:

Rich (BB code):
Do While sumfile <> " "

It should be:

Rich (BB code):
Do While sumfile <> ""
 
Upvote 0
This assignment expression is the wrong way round:

Code:
fninput = fname

It should be:

Code:
fname = fninput
 
Upvote 0

Forum statistics

Threads
1,216,070
Messages
6,128,612
Members
449,460
Latest member
jgharbawi

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