On Error GoTo skip needs help

  • Thread starter Thread starter dan
  • Start date Start date
D

dan

"Subscript out of range" appeared when a non existant file was entered,
and the execution was aborted.
Can you help me to continue the execution?

Sub Analyse()
Dim Ans As Variant
Dim filename As String
Sheets("Sheet1").Select
Ans = InputBox(prompt:="Enter the data file name. ")
If Ans = "" Then Exit Sub
filename = Ans & ".csv"
On Error GoTo skip
Workbooks.Open filename:="F:\Cabinet1\" & filename, UpdateLinks:=0
' Main analysis body here
Exit Sub
skip:
Windows("ABC").Activate
Sheets("Sheet1").Range("H1") = Ans & " file does not exist!"
End Sub
 
I'd guess Windows("ABC").Activate is failing. How about
Sheets("Sheet1").Activate instead?

--
Jim
| "Subscript out of range" appeared when a non existant file was entered,
| and the execution was aborted.
| Can you help me to continue the execution?
|
| Sub Analyse()
| Dim Ans As Variant
| Dim filename As String
| Sheets("Sheet1").Select
| Ans = InputBox(prompt:="Enter the data file name. ")
| If Ans = "" Then Exit Sub
| filename = Ans & ".csv"
| On Error GoTo skip
| Workbooks.Open filename:="F:\Cabinet1\" & filename, UpdateLinks:=0
| ' Main analysis body here
| Exit Sub
| skip:
| Windows("ABC").Activate
| Sheets("Sheet1").Range("H1") = Ans & " file does not exist!"
| End Sub
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top