File Not Found Error Message

Lucasaran

New Member
Joined
Jun 22, 2016
Messages
15
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?

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:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
For anyone who may encounter a similar problem in the future, the issue was solved by changing the macro settings within the trust center settings to "Enable all macros."

This had me stumped for a couple of hours... then I figured it out myself shortly after posting my question. Go figure. :)
 
Upvote 0
For anyone who may encounter a similar problem in the future, the issue was solved by changing the macro settings within the trust center settings to "Enable all macros."

This had me stumped for a couple of hours... then I figured it out myself shortly after posting my question. Go figure. :)


I was about to post this update to your code as you re-posted but see if changes do what you want


Code:
Sub Perform_Update()
    Dim SourceWS As Worksheet
    Dim WbToUpdate As Workbook
    Dim FileStr As Variant
    
    On Error GoTo myerror
'Set the source sheet
    Set SourceWS = ThisWorkbook.Sheets("Scan Entry")
    
'Choose (and open) the file to update
    FileStr = Application.GetOpenFilename
    If FileStr = False Then Exit Sub
    
    Application.ScreenUpdating = False
    Set WbToUpdate = Workbooks.Open(FileStr, False, False)
    
'Make changes to specified sheets in the chosen file (if applicable)
'NOTE this code is subject to change with each update
    With WbToUpdate.Sheets("Scan Entry")
        If Application.CountA(.Range("BB2:BB5")) = 0 Then
            .Range("CE1:CE7") = SourceWS.Range("CE1:CE7").Value
            .Columns("CE:CF").Hidden = True
'Save updated file
    WbToUpdate.Save
        End If
    End With
    
myerror:
'close file
    If Not WbToUpdate Is Nothing Then WbToUpdate.Close False
    Application.ScreenUpdating = True
'report errors
    If Err <> 0 Then MsgBox (Error(Err)), 48, "Error"
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,245
Members
448,555
Latest member
RobertJones1986

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top