Open Workbook

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have the following code that opens a csv file

It comes up with message canot find file.

The full name is BR1 EL Br1 EL Service RepairOrderRegister.csv

The start name for eg Br1 and the word service is important

I need to amend the code below using wilcard characters so I do not have to use the full name
Code:
 TheFile = Dir(ThePath & "BR1 Service" & "*.csv")



Code:
 Sub Open_Workbook()
ChDir ("C:\extract")
Sheets(2).Delete

Dim nb As Workbook, tw As Workbook, ts As Worksheet, TheFile As String, ThePath As String
ThePath = "C:\extract\"
TheFile = Dir(ThePath & "BR1 Service" & "*.csv")



If TheFile = "" Then Exit Sub
With Application
    .ScreenUpdating = False
    End With
Set tw = ThisWorkbook
Set ts = tw.ActiveSheet
Set nb = Workbooks.Open(TheFile)


nb.Sheets(1).Copy After:=Workbooks("BR1 Service Sales.xlsm").Sheets(1)
 Sheets(2).Name = "Imported Data"
 ChDir ("C:\my documents")
 
 End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
The filename doesn't start with "BR1 Service"

Try

Code:
Dir(ThePath & "BR1*Service*.csv")
 
Upvote 0

Forum statistics

Threads
1,214,382
Messages
6,119,194
Members
448,874
Latest member
Lancelots

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