OK, let's make sure that we are on the same page here with all the details:
1. Which file is this VBA code in?
2. What is the name of the module the VBA code is in?
3. Which line iis currently erroring, and what is the exact error message?
4. If you have made any changes to the VBA code since last posting it, re-post the version you are using now.
1. VBA code is not in any file (i.e. file 1 and file 2) it is in another file which I named Book1.
2. it is named module 1
3. While running your original code no line currently erroring. if i use your later code it gives error on line 'wb2.Worksheet(ws.Name).Range(“A2”).Paste'
4. I am posting the code here
Sub Get_Data_From_File()
Dim file1 As Variant
Dim wb1 As Workbook
Dim file2 As Variant
Dim wb2 As Workbook
Dim ws As Worksheet
Application.ScreenUpdating = False
' Browse for data file and open it
file1 = Application.GetOpenFilename(Title:="Browse for your Data File", FileFilter:="Excel Files (*.xls*),*xls*")
If file1 <> False Then
Set wb1 = Application.Workbooks.Open(file1)
End If
' Browse for template file and open it
file2 = Application.GetOpenFilename(Title:="Browse for your Template File", FileFilter:="Excel Files (*.xls*),*xls*")
If file2 <> False Then
Set wb2 = Application.Workbooks.Open(file2)
End If
' Loop through all sheets in data file and copy over to template file
wb2.Activate
For Each ws In wb1.Worksheets
ws.Cells.Copy
wb1.Activate
Sheets(ws.Name).Activate
Range("A1").Select
'wb2.Worksheet(ws.Name).Range(“A2”).Paste
ActiveSheet.Paste
Application.CutCopyMode = False
Next ws
' Close data files
wb1.Close
Application.ScreenUpdating = True
MsgBox "Macro complete!"
End Sub