Re: Why does this simple Sub fail?



You have option explicit and failed to dim

--
Don Guillett
SalesAid Software
donaldb@xxxxxxx
<NoSpam99989@xxxxxxx> wrote in message
news:du7mo1hvlaetvlc9vdd68ljv5iu41q68hb@xxxxxxxxxx
> The following is all the code in ThisWorkbook
> Option Explicit
>
> Private Sub WorkBook_Open()
> Worksheets("LB").Range("A1:E1000").Clear 'Fail 1
> CurrentEntry = -1
> Worksheets("Main").Select 'Fail 2
> Srch.Show
> End Sub
>
> This code fails with the message:
> Run time error '57121':
> Application-defined or object-defined error
>
> The failure occurs on the line marked 'Fail 1
> If I move the execution point to the next line and press F5 it fails with
> the same message at the line marked 'Fail 2
> If, at any point, I stop execution and re-execute the sub (by pressing F5)
> it runs fine.
>
> Work*** "LB" exists and is hidden
> Work*** "Main" exists, is not hidden and is on top at open. (The select
> statement is just incase the workbook was stopped with another work***
> displayed.)
>
> Remember this Sub works fine if I do nothing but stop and restart
> execution.
>
> Thanks very much for any help.


.