I am an excel vba newbie and having trouble with something simple. I have two excel workbooks; Book 1 and Book 2. I am trying to copy data from particular cells in Book 2 to Book 1. Also Book 2 is a Read Only file and is pwd protected against modifications. I am writing my code in Book 1 and want to set it to a variable.
Dim wb1 As Workbook
Dim wb2 As Workbook
Set wb1 = ThisWorkbook
wb1.Worksheets("Sheet1").Cells(1, 1).Activate
Set wb2 = Workbooks.Open("C:\Users\self\Desktop\qc\Book2.xlsm")
But I keep getting Subscript Out of Range
Error when I try to activate wb1.sheet1
. Also when I run the Set wb2
code on its own, it opens the file but goes directly to the VBA editor of that file and not the spreadsheet. I would be very grateful for any guidance on this vexing problem. Thanks in anticipation.