Dear All
I am working on a code to copy specific sheet to a new work book in excel but the code copies all the sheets although I define the sheet by name, My code is as below:
So Why it is copying all the File despite of the WS.Name ??
Notice : The Same Code Copies only One Sheet in VBA
Thanks your reply, Regards
Moheb Labib
I am working on a code to copy specific sheet to a new work book in excel but the code copies all the sheets although I define the sheet by name, My code is as below:
Code:
Private Sub ExportStockReport_T08()
Dim xl As New Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim SaveToDirectory As String
SaveToDirectory = "C:\Patches\Exports"
xl.DisplayAlerts = False
wb = xl.Workbooks.Open("C:\Patches\Main_Master_VB.xlsm")
For Each ws In wb.Sheets
If ws.Name = "FinalStockReport_T08" Then
ws.Copy()
wb.Activate()
With wb
.SaveAs(Filename:=("C:\Patches\Exports\" & ws.Name & "_" & DateTime.Now.ToString("dd-MMM-yyyy") & ".xlsm"))
.Close(False)
End With
End If
Next
xl.DisplayAlerts = True
xl.Quit()
End Sub
Notice : The Same Code Copies only One Sheet in VBA
Thanks your reply, Regards
Moheb Labib