Excel VBA code needed

naveenhs5

New Member
Joined
Mar 15, 2011
Messages
4
Hello,
There are three excel files in a folder which I want to open using VBA code.
Thing is that three files have a different file name, only common word is "....data with...xls", "....data without....xls"
Request your help on this...

Thanks,
 

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.
Try:
Rich (BB code):
Option Explicit
    
Sub exa()
Dim Path As String, Pattern As String, sFullName As String
Dim wb As Workbook
    
    '// Supply or alter path to suit.   //
    Path = "G:\2011\2011-03-14\"
    Pattern = "*data with*.xls"
    
    sFullName = Dir(Path & Pattern)
    
    Do While Not sFullName = vbNullString
        Set wb = Workbooks.Open(sFullName)
        MsgBox "do something with " & wb.Name
        wb.Close False
        
        sFullName = Dir
    Loop
End Sub
 
Upvote 0
Hello,

Thank u very much for ur time...

Briefly...there are 3 files namely APS Queues.xls and IPS _ without_SAP_Document_Number.xls and IPS _with_SAP_Doc_Number.xls

Your code works perfectly and opens the file "APS Queues.xls", but gives me a run time error 1004 for other two files saying "File does not exist or check the location" (after amending the file name accordingly in the code..eg:*with*.xls and *without.xls*). But the file name and path is correct

Pls help
 
Upvote 0
Hello,

Thank u very much for ur time...

Briefly...there are 3 files namely APS Queues.xls and IPS _ without_SAP_Document_Number.xls and IPS _with_SAP_Doc_Number.xls

Your code works perfectly and opens the file "APS Queues.xls", but gives me a run time error 1004 for other two files saying "File does not exist or check the location" (after amending the file name accordingly in the code..eg:*with*.xls and *without.xls*). But the file name and path is correct

Pls help
<!-- / message -->
 
Upvote 0
Hi,

I am not understanding. My code should open the workbook if 'data with' is in the filename. It should not open 'APS Queues.xls'. If you altered the code, can you show us the current code and actual workbook names to open?
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,357
Members
452,907
Latest member
Roland Deschain

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