Re: Why does this simple Sub fail?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.
>
> Worksheet "LB" exists and is hidden
> Worksheet "Main" exists, is not hidden and is on top at open. (The select
> statement is just incase the workbook was stopped with another worksheet
> displayed.)
>
> Remember this Sub works fine if I do nothing but stop and restart
> execution.
>
> Thanks very much for any help.


.



Relevant Pages

  • Re: Protection - Allow Group/Ungroup but lock / unlock some cells
    ... If you already have the outline/subtotals/autofilter applied, you can protect ... the worksheet in code. ... Option Explicit ... Sub auto_open ...
    (microsoft.public.excel.misc)
  • Re: XLS To CSV Macro
    ... Is there more than one worksheet in each workbook? ... Private Sub Workbook_BeforeSave ... >> Option Explicit ...
    (microsoft.public.excel)
  • Re: Using Validation to force entry into cells?
    ... My first guess is that you opened the workbook with macros disabled. ... And if you need this same code for every worksheet in the workbook, ... Private Sub Workbook_SheetChange ... > Option Explicit ...
    (microsoft.public.excel.misc)
  • Re: Using Validation to force entry into cells?
    ... Uh oh...I run into a problem now with every copy of this worksheet. ... Private Sub Worksheet_Change ... > Option Explicit ... >> entry into this column in our form. ...
    (microsoft.public.excel.misc)
  • Re: Questions concerning VBA coding
    ... Thank you so much Dave. ... What is the "Option Explicit" and the "On Error ... Sub Copy_Template ... > have a worksheet named "Template". ...
    (microsoft.public.excel.misc)