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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

daverunt

Well-known Member
Joined
Jul 9, 2009
Messages
1,893
Office Version
  1. 2013
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,133,718
Messages
5,660,482
Members
418,580
Latest member
IrishDave2137

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
Top