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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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