• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User


  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Compare 2 workbooks


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.

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"
  Set wsnew = owb.Sheets.Add
  wsnew.Name = a
  End If
Next ws1
Next ws