Dear all,
I am having a quite difficulty regarding VBA.
Currently, I am trying to duplicate an excel sheet that is from another workingfile with application of VBA on current working file.
Sub BringingSheet()
Dim fileName As String
Dim filePath As String
Dim shtName As String
Dim NewlyCreatedFile As Workbook
Set NewlyCreatedFile = Workbooks.Add
' To be Duplicated
Dim i As Integer
Dim n As Integer
'Input of the file that has the sheet to be duplicated
file = ThisWorkbook.Sheets("Sheet1").Cells(2, 3).Value
'Input of the number that is to be outputed
n = ThisWorkbook.Sheets("Sheet1").Cells(4, 3).Value
'Path of the sheet to be duplicated
filePath = ThisWorkbook.Path + "\" + file
'Opening of the file
Workbooks.Open fileName:=filePath
'Bringing the copy - loop // 1 is the name of the sheet
For i = 1 To n
ActiveWorkbook.Sheets("1").Copy After:=NewlyCreatedFile.Sheets(1)
Next
Workbooks(file).Close (False)
End Sub
Additionally, I would like the sheet to be numbered as 1, 2, 3...to n
Thanks
I am having a quite difficulty regarding VBA.
Currently, I am trying to duplicate an excel sheet that is from another workingfile with application of VBA on current working file.
Sub BringingSheet()
Dim fileName As String
Dim filePath As String
Dim shtName As String
Dim NewlyCreatedFile As Workbook
Set NewlyCreatedFile = Workbooks.Add
' To be Duplicated
Dim i As Integer
Dim n As Integer
'Input of the file that has the sheet to be duplicated
file = ThisWorkbook.Sheets("Sheet1").Cells(2, 3).Value
'Input of the number that is to be outputed
n = ThisWorkbook.Sheets("Sheet1").Cells(4, 3).Value
'Path of the sheet to be duplicated
filePath = ThisWorkbook.Path + "\" + file
'Opening of the file
Workbooks.Open fileName:=filePath
'Bringing the copy - loop // 1 is the name of the sheet
For i = 1 To n
ActiveWorkbook.Sheets("1").Copy After:=NewlyCreatedFile.Sheets(1)
Next
Workbooks(file).Close (False)
End Sub
Additionally, I would like the sheet to be numbered as 1, 2, 3...to n
Thanks