Hello All
I have a requirement in excel macro.
I have 2 workbooks, Say A and B
A Workbook contains, sheet 1, sheet2 and sheet3
B Workbook contains sheet4
Now i need to compare 2 workbooks, if missing sheets in Workbook B, then need to add sheets from Workbook A
So finally, B workbook should contain : Sheet 1, sheet 2, sheet 3 and sheet 4.
Tried below code but its not working.
I have a requirement in excel macro.
I have 2 workbooks, Say A and B
A Workbook contains, sheet 1, sheet2 and sheet3
B Workbook contains sheet4
Now i need to compare 2 workbooks, if missing sheets in Workbook B, then need to add sheets from Workbook A
So finally, B workbook should contain : Sheet 1, sheet 2, sheet 3 and sheet 4.
Tried below code but its not working.
Code:
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