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
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
So after some more fun of trying things, this is the line where it hangs up and yields the error message:

o_id(x) = wsOut.Range(wsOut.Cells(1, i - 3)).Value

I'm not sure how this is the case, up to this line I am able to access the workbook/sheets. I acknowledge there could be better ways to grab the data, but this *should* work, no?
I've tried removing the wsOut references, I've added wbOut references and they don't make any changes in this error, currently.
 
Upvote 0
That line should be
VBA Code:
o_id(x) = wsOut.Cells(1, i - 3).Value
 
Upvote 0
I cannot see how you would get an "The file specified cannot be found." error on that line. I would expect that error to occur here
VBA Code:
Set wbOut = Workbooks.Open(ODpath)
When you get the error, click debug, what line of code is highlighted?
 
Upvote 0
I do not receive any portion of code that is highlight. Clicking the debug drop down, there does not appear any useful tools while working in this module.
I know I can place a message box just before the o_id line and it will appear, as soon as 'OK' is selected the error prompt appears.
 
Upvote 0
When you get the error is there a button marked Debug?
 
Upvote 0
The attached is all I see, I can't scroll through the VBA code while this prompt is up.
 

Attachments

  • Capture_ME.JPG
    Capture_ME.JPG
    15.9 KB · Views: 7
Upvote 0
That looks more like a message box. Check your code, including the calling routine & see if it has any error handling that includes that message
 
Upvote 0
Solution
I was not aware that the OnError command from my main code would perform the same function when in a module. I have found my Type mismatch issue. Thanks for your help!
 
Upvote 0

Forum statistics

Threads
1,214,973
Messages
6,122,534
Members
449,088
Latest member
RandomExceller01

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