dreen
Board Regular
- Joined
- Nov 20, 2019
- Messages
- 52
I have read other posts and I still can't seem to figure out what I am doing wrong... I have two workbooks, one with the code in it (Sheet1 is the codename of the sheet I want to copy values from) and another workbook defined as "y" in this example. I want to copy over the value of K1 in Sheet1 into cell F5 of workbook y.
Nothing is happening when I hit the Command button (It is an Activex commandbutton, so I have put it in the Worksheet), nothing is even opening. I have double checked the file paths and the sheet names as well, they are correct.
I have also posted screenshots of the code and both workbooks below:
Nothing is happening when I hit the Command button (It is an Activex commandbutton, so I have put it in the Worksheet), nothing is even opening. I have double checked the file paths and the sheet names as well, they are correct.
I have also posted screenshots of the code and both workbooks below:
VBA Code:
Private Sub Commandbutton1_Click()
Dim y As Workbook
Set y = Workbooks.Open("FILEPATH\Databases\Test 2.xlsm")
Sheet1.Unprotect "Swarf"
y.Unprotect "Swarf"
y.Sheets("Mytest2").Range("F5").Value = Sheet1.Range("K1").Value
y.Protect "Swarf"
y.Close SaveChanges = True
Sheet1.Protect “Swarf”
End Sub