Opens file, sends error file cannot be found.

R2ah1ze1l

Board Regular
Joined
Nov 10, 2017
Messages
93
I am opening a file, and able to count the cells occupied. Upon attempting to copy data from certain cells, I am receiving a Microsoft Excel error: "The file specified cannot be found. Check the spelling and try again." I used MsgBox to locate my area of issue, but I cannot seem to understand what cannot be found..
Code:
Sub Requirements(wsReview As Worksheet, out_title As String, out_dims As String, ODpath As String)

Dim wbOut As Workbook, wsOut As Worksheet
Dim o_id() As Double, o_n() As Double, o_pt() As Double, o_mt() As Double

strfileexists = Dir(ODpath)
If strfileexists = "" Then
Application.WindowState = xlMaximized
MsgBox ("File: " & ODpath & " not found.")
 GoTo Leave_sub
End If

Set wsReview = wsReview

Set wbOut = Workbooks.Open(ODpath)
Set wsOut = wbOut.Worksheets(out_title)

outc = 0

wsOut.Activate
wsOut.Range("A1").Activate

While Not ActiveCell = ""
outc = outc + 1
ActiveCell.Offset(0, 1).Activate
Wend
rowc = outc / 4

ReDim o_id(1 To rowc) As Double
ReDim o_n(1 To rowc) As Double
ReDim o_pt(1 To rowc) As Double
ReDim o_mt(1 To rowc) As Double
MsgBox ("Passed Redim")        '<This message appears prior to the error

i = 0
x = 0
wsOut.Activate
While x < rowc
x = x + 1
i = x * 4
o_id(x) = wsOut.Range(wsOut.Cells(1, i - 3)).Value
o_n(x) = wsOut.Range(wsOut.Cells(1, i - 2)).Value
o_pt(x) = wsOut.Range(wsOut.Cells(1, i - 1)).Value
o_mt(x) = wsOut.Range(wsOut.Cells(1, i)).Value
Wend
MsgBox ("Collected data")      '<This message does not appear prior to error

x = 0
wsReview.Activate
wsReview.Range("F11").Activate
While x < rowc
x = x + 1
wsReview.Range(wsReview.Cells(ir + x, 6)).Value = o_id(x)
wsReview.Range(wsReview.Cells(ir + x, 7)).Value = o_n(x)
wsReview.Range(wsReview.Cells(ir + x, 8)).Value = o_pt(x)
wsReview.Range(wsReview.Cells(ir + x, 9)).Value = o_mt(x)
Wend

wsOut.Activate
ActiveWorkbook.Close

Leave_sub:
End Sub
 
I was not aware that the OnError command from my main code would perform the same function when in a module.
Yup, it percolates down through all procedures that get called.
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,214,832
Messages
6,121,849
Members
449,051
Latest member
excelquestion515

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