I've written code to change the contents of a cell in multiple protected workbooks looking up the value to be inserted from a table in my worksheet.
The issue I have is that when I select a file in the \Files\
folder, it opens up the VBA editor showing the code I'm using. The window opens even if Excel is closed and after a fresh restart.
It's not really a bug. It's just quite annoying as I'm using the preview mode in file explorer to double check the code has worked.
Files are stored in c:\Folder\
.
A list of the file names is in column A starting in row 2 with corresponding values to be updated in column B.
Paste location is cell F2 of sheet 'References'
Sub UpdateFiles()
Dim rownum As Long
rownum = 2
Dim last_row As Long
last_row = Cells(Rows.Count, 1).End(xlUp).Row
Dim filename As String
Dim newvalue As Long
For nextRow = 2 To last_row
filename = Range("A" & rownum).Value
newvalue = ActiveWorkbook.Sheets("Sheet1").Range("B" & rownum).Value
Workbooks.Open "C:\Folder\" & filename
ActiveWorkbook.Unprotect ("password")
ActiveWorkbook.Sheets("References").Range("F2") = newvalue
ActiveWorkbook.Protect ("password")
ActiveWorkbook.Save
ActiveWorkbook.Close
rownum = rownum + 1
Next nextRow
End Sub