VBA open file with partial name

Holdenfreak

New Member
Joined
Nov 3, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I would like to run a code to open a .xls file and check a specific cell in that file. The file names are variable and based in invoice number ie ACC003-SS-D9927. I would like to be able to search for just "D9927" the "ACC003... part is variable. i will also be searching multiple folders with a directory (W:\EAL\ARCHIVE EAL REPORTS). I will probably do this via a userform and textbox to set the job number search.

Can anyone help as to how to open the specified files

Cheers

Holdenfreak
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
loop the files in the folder with DIR and use a LIKE and wildcard (*) on the filename to identify the correct file?
 
Upvote 0
VBA Code:
Sub LoopThroughFiles()
    Dim StrFile As String
    StrFile = Dir("C:\")
    Do While Len(StrFile) > 0
        If StrFile Like "*.xlsx" Then Debug.Print StrFile
        StrFile = Dir
    Loop
End Sub

simple version loops the cdrive and prints any .xlsx files
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,287
Members
448,562
Latest member
Flashbond

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