I have hundreds of workbook that contain data that have to be pasted onto respective workbooks and I wrote 4 modules.
Sub AllFiles()
Dim folderPath As String
Dim filename As String
Dim wb As Workbook
folderPath = "C:\Users\HKIEd\Downloads" 'change to suit
If Right(folderPath, 1) <> "" Then folderPath = folderPath + ""
filename = Dir(folderPath & "*.xls")
Do While filename <> ""
Application.ScreenUpdating = False
Set wb = Workbooks.Open(folderPath & filename)
'Call a subroutine here to operate on the just-opened workbook
Call Copy
filename = Dir
Loop
Application.ScreenUpdating = True
End Sub
Sub Copy()
'
' Macro1 Macro
'
'
Sheets(1).Select
Range("B2:B81").Select
Range("B81").Activate
Selection.Copy
Call Pastesrc
End Sub
Sub Pastesrc()
Dim folderPath As String
Dim filename As String
Dim wb As Workbook
folderPath = "C:\Users\HKIEd\Documents" 'change to suit
If Right(folderPath, 1) <> "" Then folderPath = folderPath + ""
filename = Dir(folderPath & "*.xls")
Do While filename <> ""
Application.ScreenUpdating = False
Set wb = Workbooks.Open(folderPath & filename)
'Call a subroutine here to operate on the just-opened workbook
Call Paste
filename = Dir
Loop
Application.ScreenUpdating = True
End Sub
Sub Paste()
Sheets(1).Select
ActiveSheet.Unprotect "abc"
Range("A4").Activate
Range("A4").Select
ActiveSheet.PasteSpecial Paste:=xlPasteValues
ActiveSheet.Protect "abc"
End Sub
However, it gets stuck at ActiveSheet.PasteSpecial Paste:=xlPasteValues. I am new to VBA, not sure what happened and not sure if I got the scripts right. Pls help!!
Actually I would like the name of the source to match with that of the destination when the data is copied and pasted but I have no idea how to do so.Pls help!!!!
Thanks a great great deal
Sub AllFiles()
Dim folderPath As String
Dim filename As String
Dim wb As Workbook
folderPath = "C:\Users\HKIEd\Downloads" 'change to suit
If Right(folderPath, 1) <> "" Then folderPath = folderPath + ""
filename = Dir(folderPath & "*.xls")
Do While filename <> ""
Application.ScreenUpdating = False
Set wb = Workbooks.Open(folderPath & filename)
'Call a subroutine here to operate on the just-opened workbook
Call Copy
filename = Dir
Loop
Application.ScreenUpdating = True
End Sub
Sub Copy()
'
' Macro1 Macro
'
'
Sheets(1).Select
Range("B2:B81").Select
Range("B81").Activate
Selection.Copy
Call Pastesrc
End Sub
Sub Pastesrc()
Dim folderPath As String
Dim filename As String
Dim wb As Workbook
folderPath = "C:\Users\HKIEd\Documents" 'change to suit
If Right(folderPath, 1) <> "" Then folderPath = folderPath + ""
filename = Dir(folderPath & "*.xls")
Do While filename <> ""
Application.ScreenUpdating = False
Set wb = Workbooks.Open(folderPath & filename)
'Call a subroutine here to operate on the just-opened workbook
Call Paste
filename = Dir
Loop
Application.ScreenUpdating = True
End Sub
Sub Paste()
Sheets(1).Select
ActiveSheet.Unprotect "abc"
Range("A4").Activate
Range("A4").Select
ActiveSheet.PasteSpecial Paste:=xlPasteValues
ActiveSheet.Protect "abc"
End Sub
However, it gets stuck at ActiveSheet.PasteSpecial Paste:=xlPasteValues. I am new to VBA, not sure what happened and not sure if I got the scripts right. Pls help!!
Actually I would like the name of the source to match with that of the destination when the data is copied and pasted but I have no idea how to do so.Pls help!!!!
Thanks a great great deal