Open 40 files at once and copy paste special values

praveenlal

New Member
Joined
Oct 27, 2021
Messages
34
Office Version
  1. 2016
Platform
  1. Windows
I have 40 different files with same format. I want to open all 40 files at once and copy paste special values in 2 cells. Can anyone help with it.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
something similar to this , that opens all xl files in 1 folder (given in cell D7)
then opens all and copies src cell to target cell.

Code:
Dim wbSrc As Workbook, wb As Workbook
Const kTargCell = "C4"
  'goto source file to copy from
 
Workbooks.Open "c:\temp\mySource.xls"
Set wbSrc = ActiveWorkbook
  'open all wb's in 1 folder
OpenAllFilesInDir Range("D7").Value
'goto each wb and paste
For Each wb In Workbook
    wbSrc.Activate
    Range(kTargCell).Copy
   
    wb.Activate
    Range(kTargCell).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    wb.Close True
Next
Set wb = Nothing
Set wbSrc = Nothing
End Sub

Private Sub OpenAllFilesInDir(ByVal pvDir)
Dim vFil, vTargT
Dim i As Integer
Dim sSql As String
Dim db 'As Database
Dim fso
Dim oFolder, oFile
On Error GoTo errImp
If Right(pvDir, 1) <> "\" Then pvDir = pvDir & "\"
'sTBL = "xlFile"
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(pvDir)
For Each oFile In oFolder.Files
    vFil = oFile.Name
    If InStr(vFil, ".xls") > 0 Then      'ONLY DO EXCEL FILES
       Workbooks.Open oFile
    End If
Next
Set db = Nothing
Set fso = Nothing
Set oFile = Nothing
Set oFolder = Nothing
Exit Sub
errImp:
MsgBox Err.Description, vbCritical, "ImportAllFilesInDir():" & Err
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,595
Members
449,089
Latest member
Motoracer88

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