VBA - Open files and copy certain data

prabby25101981

Active Member
Joined
Jul 28, 2010
Messages
348
Hi Guys,

Can someone guide as to how I can one by one open all files in one folder, copy certain data from each of the file, and paste it in another file through VBA?

I am pretty much OK with VBA but have never used file and folder codes...

Thanks!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Something along these lines?


Code:
'Select ResultFile
    ResultFile = Application.GetOpenFilename("Excel Files (*.xls*)," & _
    "*.xls*", 1, "Select Result file", "Open", False)
 
'If the user cancels then exit
    If TypeName(ResultFile) = "Boolean" Then
        Exit Sub
    End If
 
'Open Result File
    Workbooks.Open ResultFile
    ResultFile = Dir(ResultFile)
 
 
'Select source file directory
  SourceFile = Application.GetOpenFilename("Excel Files (*.xls*)," & _
    "*.xls*", 1, "Select Source Files", "Open", False)
 
'If the user cancels then exit
   If TypeName(SourceFile) = "Boolean" Then
        Exit Sub
    End If
 
'Set xls as SourceFile
      SourceFile = Dir("*.xls")
 
  Do While SourceFile <> ""
 
       x = 1
       Workbooks.Open SourceFile
       Set XLSFile = ActiveWorkbook
       x = x + 1
 
       ---------------Do something with the source file-------------------       
'Activate the result file               
       Windows(ResultFile).Activate
 
     ---------------Do something with the result file-------------------    
 
 
 'Close open source file
    XLSFile.Close False
 
  SourceFile = Dir
  Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,093
Latest member
catterz66

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