user2220670
user2220670

Reputation: 125

Excel comments not being pasted after copy

I am trying to copy and paste comments from one Excel workbook to another, but the comments don't get pasted after being copied from the first workbook.

Here is my code:

  Sub Comments()
    Dim x As Workbook
    Dim y As Workbook

    Set x = Workbooks.Open("C:\Exportbook.xlsx")
    Set y = ActiveWorkbook

    x.Sheets("Tablets").Range("E10:AQ2000").Copy
    y.Sheets("Tablets").Range("E10:AQ2000").PasteSpecial Paste:=xlPasteComments

    x.Close SaveChanges:=False

  End Sub

Upvotes: 2

Views: 194

Answers (1)

Greg
Greg

Reputation: 426

You need to use ThisWorkbook instead of ActiveWorkbook.

Currently your code copies and pastes from/to the same location. After opening workbook x it will become the active workbook, so workbook y is the same as workbook x.

Upvotes: 1

Related Questions