close

quot;Subscript out of rangequot; 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(quot;Sheet1quot;).Select
Ans = InputBox(prompt:=quot;Enter the data file name. quot;)
If Ans = quot;quot; Then Exit Sub
filename = Ans amp; quot;.csvquot;
On Error GoTo skip
Workbooks.Open filename:=quot;F:\Cabinet1\quot; amp; filename, UpdateLinks:=0
' Main analysis body here
Exit Sub
skip:
Windows(quot;ABCquot;).Activate
Sheets(quot;Sheet1quot;).Range(quot;H1quot;) = Ans amp; quot; file does not exist!quot;
End Sub
I'd guess Windows(quot;ABCquot;).Activate is failing. How about
Sheets(quot;Sheet1quot;).Activate instead?

--
Jim
quot;danquot; gt; wrote in message
news:IU63g.200$ud.152@trndny03...
| quot;Subscript out of rangequot; 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(quot;Sheet1quot;).Select
| Ans = InputBox(prompt:=quot;Enter the data file name. quot;)
| If Ans = quot;quot; Then Exit Sub
| filename = Ans amp; quot;.csvquot;
| On Error GoTo skip
| Workbooks.Open filename:=quot;F:\Cabinet1\quot; amp; filename, UpdateLinks:=0
| ' Main analysis body here
| Exit Sub
| skip:
| Windows(quot;ABCquot;).Activate
| Sheets(quot;Sheet1quot;).Range(quot;H1quot;) = Ans amp; quot; file does not exist!quot;
| End Sub
|
|
Hi, Jim
You are right. It should be Windows(quot;ABC.xlsquot;).Activate
Thank you for pointing out.

quot;Jim Rechquot; gt; wrote in message
...
gt; I'd guess Windows(quot;ABCquot;).Activate is failing. How about
gt; Sheets(quot;Sheet1quot;).Activate instead?
gt;
gt; --
gt; Jim
gt; quot;danquot; gt; wrote in message
gt; news:IU63g.200$ud.152@trndny03...
gt; | quot;Subscript out of rangequot; appeared when a non existant file was entered,
gt; | and the execution was aborted.
gt; | Can you help me to continue the execution?
gt; |
gt; | Sub Analyse()
gt; | Dim Ans As Variant
gt; | Dim filename As String
gt; | Sheets(quot;Sheet1quot;).Select
gt; | Ans = InputBox(prompt:=quot;Enter the data file name. quot;)
gt; | If Ans = quot;quot; Then Exit Sub
gt; | filename = Ans amp; quot;.csvquot;
gt; | On Error GoTo skip
gt; | Workbooks.Open filename:=quot;F:\Cabinet1\quot; amp; filename,
gt; UpdateLinks:=0
gt; | ' Main analysis body here
gt; | Exit Sub
gt; | skip:
gt; | Windows(quot;ABCquot;).Activate
gt; | Sheets(quot;Sheet1quot;).Range(quot;H1quot;) = Ans amp; quot; file does not exist!quot;
gt; | End Sub
gt; |
gt; |
gt;
gt;

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()