I have same type of files generated monthly. Datafiles are having same name but they are on different folders. What I want is to copy a specific column (computed result) of previous month's datafile to new month's datafile. I have tried . But couldn't get it. I am getting this error. "VBA Object doesn't support this property or method"
My code is
Private Sub CommandButton1_Click()
Dim CSVfolder, CSVfolder1, CSVfolder2 As String
Dim XlsFolder, XlsFolder1, XlsFolder2 As String
Dim fname, fname1, fname2 As String
Dim wBook As Workbook
Dim vArr, vArr1, vArr2
Dim vFile, vFile1, vFile2
vArr = Array("Bangalore")
CSVfolder = "C:\Charts\0\"
CSVfolder1 = "C:\Charts\1\"
CSVfolder2 = "C:\Charts\2\"
XlsFolder = "C:\Charts\0\"
XlsFolder1 = "C:\Charts\1\"
XlsFolder2 = "C:\Charts\2\"
vArr1 = Array("Bangalore")
vArr2 = Array("Bangalore")
Dim fileName, Pathname As String
Dim WB, WB1, WB2 As Workbook
Pathname = "c:\Charts\0\"
Dim fileName1, Pathname1 As String
Pathname1 = "c:\Charts\1\"
For Each vFile1 In vArr1
fileName1 = Dir(Pathname1 & vFile1 & "\" & "*.xlsx")
Do While fileName1 <> ""
Set WB1 = Workbooks.Open(Pathname1 & vFile1 & "\" & fileName1)
WB1.Application.ScreenUpdating = False
WB1.ActiveSheet.Columns("M").Copy
ActiveSheet.Close SaveChanges:=False
Workbooks.Open (Pathname & vFile & "\" & fileName1)
ActiveSheet.Columns("C").Select
ActiveSheet.Paste
ActiveSheet.Close SaveChanges:=True
Loop
Next
Dim fileName2, Pathname2 As String
Pathname2 = "c:\Charts\2\"
For Each vFile2 In vArr2
fileName2 = Dir(Pathname1 & vFile2 & "\" & "*.xlsx")
Do While fileName2 <> ""
Set WB2 = Workbooks.Open(Pathname2 & vFile2 & "\" & fileName2)
WB2.Application.ScreenUpdating = False
WB2.ActiveSheet.Columns("M").Copy
WB2.ActiveSheet.Close SaveChanges:=False
Workbooks.Open (Pathname & vFile & "\" & fileName2)
ActiveSheet.Columns("D").Select
ActiveSheet.Paste
ActiveSheet.Close SaveChanges:=True
Loop
Next
End Sub
I want to open a file . Copy a column. close it. open another file with same name. paste it. .... Thats all... But error occurs. Pls help me. Thanks in advance.