gunjan8882
New Member
- Joined
- Nov 10, 2010
- Messages
- 19
Dear all.
I am getting error for the following macro for copying and pasting data to multiple sheets in the folder. It seems after saving the file, clipboard gets clear and the copy text from the file gets unselected. Hence, the copy/paste function works for the first file and gives error for the subsequent files. Kindly help to correct the code. Thanks in advance.
-----------------------------------------------------------------------------------------
Private Sub CommandButton1_Click()Dim oFSO
Dim Folder As Object
Dim Files As Object
Dim file As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set Folder = oFSO.GetFolder("J:\Flare Scenarios")
Workbooks("Page No.xlsm").Activate
ActiveSheet.Range("R2:V7").Select
Application.CutCopyMode = True
Selection.Copy
For Each file In Folder.Files
If file.Type Like "*Microsoft Excel*" Then
Workbooks.Open Filename:=file.Path
ActiveSheet.Range("C155").Select
ActiveSheet.Paste
Sheets("Module (LT)").Select
ActiveSheet.Range("C155").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWorkbook.Close SaveChanges:=True
End If
Next file
Set oFSO = Nothing
End Sub
---------------------------------------------------------------------------------------------------------------------
I am getting error for the following macro for copying and pasting data to multiple sheets in the folder. It seems after saving the file, clipboard gets clear and the copy text from the file gets unselected. Hence, the copy/paste function works for the first file and gives error for the subsequent files. Kindly help to correct the code. Thanks in advance.
-----------------------------------------------------------------------------------------
Private Sub CommandButton1_Click()Dim oFSO
Dim Folder As Object
Dim Files As Object
Dim file As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set Folder = oFSO.GetFolder("J:\Flare Scenarios")
Workbooks("Page No.xlsm").Activate
ActiveSheet.Range("R2:V7").Select
Application.CutCopyMode = True
Selection.Copy
For Each file In Folder.Files
If file.Type Like "*Microsoft Excel*" Then
Workbooks.Open Filename:=file.Path
ActiveSheet.Range("C155").Select
ActiveSheet.Paste
Sheets("Module (LT)").Select
ActiveSheet.Range("C155").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWorkbook.Close SaveChanges:=True
End If
Next file
Set oFSO = Nothing
End Sub
---------------------------------------------------------------------------------------------------------------------
Last edited: