Hi guys,
I've written some code in workbook1 that opens and edits a different workbook (specified by the user), however I am receiving an error message "File not found." There is no error code with the error message, no additional info at all actually - it doesn't even highlight a line of code upon breaking.
As far as I can tell, the error occurs in this line:
WbToUpdate.Sheets("Scan Entry").Range("BB2:BB5") = ""
That line of code executes (clearing data from the specified cells in the selected workbook), then the error message appears and the code breaks. Any ideas as to what I have done wrong?
I've written some code in workbook1 that opens and edits a different workbook (specified by the user), however I am receiving an error message "File not found." There is no error code with the error message, no additional info at all actually - it doesn't even highlight a line of code upon breaking.
As far as I can tell, the error occurs in this line:
WbToUpdate.Sheets("Scan Entry").Range("BB2:BB5") = ""
That line of code executes (clearing data from the specified cells in the selected workbook), then the error message appears and the code breaks. Any ideas as to what I have done wrong?
Code:
Sub Perform_Update()
Dim SourceWb As Workbook
Dim WbToUpdate As Workbook
Dim Sh As Worksheet
Dim CodeCom As VBIDE.VBComponent
Application.ScreenUpdating = False
'Set the source file
Set SourceWb = ThisWorkbook
'Choose (and open) the file to update
FileStr = Application.GetOpenFilename
Set WbToUpdate = Workbooks.Open(FileStr)
'Make changes to specified sheets in the chosen file (if applicable)
'NOTE this code is subject to change with each update
WbToUpdate.Sheets("Scan Entry").Range("BB2:BB5") = ""
WbToUpdate.Sheets("Scan Entry").Range("CE1") = SourceWb.Sheets("Scan Entry").Range("CE1").Value
WbToUpdate.Sheets("Scan Entry").Range("CE2") = SourceWb.Sheets("Scan Entry").Range("CE2").Value
WbToUpdate.Sheets("Scan Entry").Range("CE3") = SourceWb.Sheets("Scan Entry").Range("CE3").Value
WbToUpdate.Sheets("Scan Entry").Range("CE4") = SourceWb.Sheets("Scan Entry").Range("CE4").Value
WbToUpdate.Sheets("Scan Entry").Range("CE5") = SourceWb.Sheets("Scan Entry").Range("CE5").Value
WbToUpdate.Sheets("Scan Entry").Range("CE6") = SourceWb.Sheets("Scan Entry").Range("CE6").Value
WbToUpdate.Sheets("Scan Entry").Range("CE7") = SourceWb.Sheets("Scan Entry").Range("CE7").Value
WbToUpdate.Sheets("Scan Entry").Columns("CE:CF").Hidden = True
'Save updated file
Application.EnableEvents = False
WbToUpdate.Close SaveChanges:=True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Last edited: