Hi,
I am trying to copy data from one workbook that is on specific location and then paste data to the another workbook and then save the 'another' workbook with specific name.
I am able to save workbook but I am unable to copy data from one workbook to another. code gives an error. Below is my code. Please help.
I am trying to copy data from one workbook that is on specific location and then paste data to the another workbook and then save the 'another' workbook with specific name.
I am able to save workbook but I am unable to copy data from one workbook to another. code gives an error. Below is my code. Please help.
Code:
Sub Save214012016()
Dim FName As String
Dim FPath As String
Dim NewBook As Workbook
Dim wb2 As Workbook
FPath = "C:\Users\aman.bhardwaj\Desktop\Ideas\Learning process\Master files\testing\saved report"
FName = "LearnersinMandateDataExport_3657_" & Format(Date, "mmddyyyy") & ".xlsx"
Set wb2 = Workbooks.Open("C:\Users\aman.bhardwaj\Desktop\Ideas\Learning process\30th November 2015\raw\LearnersinMandateDataExport_3657.xls")
ThisWorkbook.Activate
Set NewBook = Workbooks.Add
Windows("LearnersinMandateDataExport_3657.xls").Activate
Sheets("Sheet1").Select
wb2.Sheets("Sheet1").Copy Before:=NewBook.Sheets(1)
If Dir(FPath & "\" & FName) <> "" Then
MsgBox "File " & FPath & "\" & FName & " already exists"
Else
NewBook.SaveAs Filename:=FPath & "\" & FName
End If
End Sub