How can run this macro in all excell files in specific folder

bigmak

New Member
Joined
Sep 8, 2020
Messages
16
Office Version
  1. 2016
Platform
  1. Windows
Hello everybody

how can run this vba code in all excell file in folder ??
this code copy some info from Book4 to Book1 .
i have 5 excell file in a folder and i want this code run in all 5 excell file same time.

VBA Code:
Sub Macro3()
    Windows("Book4.xlsm").Activate
    Range("G5:G7").Select
    Selection.Copy
    Windows("Book1.xlsm").Activate
    Range("C13").Select
    ActiveSheet.Paste
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
What is the full path to the folder containing the files? What is the file extension (xlsx, xlsm)? Are they the only files in that folder? Do you want to paste the ranges underneath each other starting at C13? Please clarify.
 
Upvote 0
What is the full path to the folder containing the files? no matter
extension = xlsm
Are they the only files in that folder? = yes
i want code select G5:G7 cells from Book4.xlsm and copy them to C13:C15 of all sheets of folder files.
 
Upvote 0
How about
VBA Code:
Sub bigmak()
   Dim Pth As String
   Dim Fname As Object
   Dim Rng As Range
   Dim ws As Worksheet
   
   Pth = "C:\mrexcel\"
   Set Rng = Range("G5:G7")
   With CreateObject("scripting.filesystemobject")
      For Each Fname In .getfolder(Pth).Files
         With Workbooks.Open(Fname)
            For Each ws In .WorkSheets
               Rng.Copy ws.Range("C13")
            Next ws
            .Close True
         End With
      Next Fname
   End With
End Sub
 
Upvote 0
یخ
How about
VBA Code:
Sub bigmak()
   Dim Pth As String
   Dim Fname As Object
   Dim Rng As Range
   Dim ws As Worksheet
 
   Pth = "C:\mrexcel\"
   Set Rng = Range("G5:G7")
   With CreateObject("scripting.filesystemobject")
      For Each Fname In .getfolder(Pth).Files
         With Workbooks.Open(Fname)
            For Each ws In .WorkSheets
               Rng.Copy ws.Range("C13")
            Next ws
            .Close True
         End With
      Next Fname
   End With
End Sub
[/QUOTE
dosnt work bro
i find this code and work great for my some work but dont work on my code that i post in first thread.
i want to get some cells info from Book4.xlsm file and copy that to all sheets of all excell files in a folder.
VBA Code:
Sub LoopThroughFiles()      
    Dim xFd As FileDialog
    Dim xFdItem As Variant
    Dim xFileName As String
    Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
    If xFd.Show = -1 Then
        xFdItem = xFd.SelectedItems(1) & Application.PathSeparator
        xFileName = Dir(xFdItem & "*.xls*")
        Do While xFileName <> ""
            With Workbooks.Open(xFdItem & xFileName)
                'your code here                                                       
            End With
            xFileName = Dir
        Loop
    End If
End Sub
 
Upvote 0
i find this code and work great for my some work but dont work on my code that i post in first thread.
i want to get some cells info from Book4.xlsm file and copy that to all sheets of all excell files in a folder.
VBA Code:
Sub LoopThroughFiles()     
    Dim xFd As FileDialog
    Dim xFdItem As Variant
    Dim xFileName As String
    Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
    If xFd.Show = -1 Then
        xFdItem = xFd.SelectedItems(1) & Application.PathSeparator
        xFileName = Dir(xFdItem & "*.xls*")
        Do While xFileName <> ""
            With Workbooks.Open(xFdItem & xFileName)
                'your code here                                                       
            End With
            xFileName = Dir
        Loop
    End If
End Sub
 
Upvote 0
Did you try the code I supplied?
 
Upvote 0

Forum statistics

Threads
1,214,589
Messages
6,120,415
Members
448,960
Latest member
AKSMITH

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