I had a requirement which is in excel macro. Here is the scenario :
I have 2 workbooks, Say A and B
Workbook "A" contains, sheet 1, sheet2 and sheet3, Workbook "B" contains sheet4
Now i need to compare Workbook "B" with Workbook A. If a sheet exist in Workbook "A" which is not in Workbook "B" (Here Sheet1, Sheet2, Sheet3) then i need to add these 3 sheets to Workbook "B"
So finally, B workbook should contain : Sheet 1, sheet 2, sheet 3 and sheet 4.
Tried below code but its not working.
Set act = ThisWorkbook
path = Sheet1.TextBox1.Text
Set owb = Workbooks.Open(Filename:=path)
For Each ws In ThisWorkbook.Worksheets
a = ws.Name
For Each ws1 In owb.Worksheets
If ws1.Name = a Then
MsgBox "Found"
Else
Set wsnew = owb.Sheets.Add
wsnew.Name = a
End If
Next ws1
Next ws