Workbook_Open() won't run macro unless breakpoint set

A

anduare2

I have this macro/code placed in "ThisWorkbook" in the VBAPProject of a 2003
excel file. The problem is it is not clearing the scroll area when the
reference field is set to "No"

Private Sub Workbook_Open()
If Worksheets("Data").Range("I16").Value = "Yes" Then
Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30006).Enabled = False
Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30007).Enabled = False
Application.CommandBars("Ply").FindControl(ID:=889).Enabled = False
Application.CommandBars("Ply").FindControl(ID:=1561).Enabled = False
Sheets("Sales").Select
Dim LastRow As Long
With Worksheets("Sales")
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
.ScrollArea = "B2:C" & LastRow
End With
ElseIf Worksheets("Data").Range("I16").Value = "No" Then
Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30006).Enabled = True
Application.CommandBars("Worksheet Menu
Bar").FindControl(ID:=30007).Enabled = True
Application.CommandBars("Ply").FindControl(ID:=889).Enabled = True
Application.CommandBars("Ply").FindControl(ID:=1561).Enabled = True
Sheets("Sales").Select
ActiveSheet.ScrollArea = ""
End If
End Sub

It acts like it will not run the macro on opening the file. If I place a
breakpoint anywhere within that routine, on open it opens the vba editor and
I can step/run thru the procedure and the worksheet is fine. Meaning the
scroll area restriction for the sales sheet has been eliminated when the
reference field is set to "No". But if vba is not triggered to open it acts
like it just skips the running of the macro and never tests the Yes/No
condition.

The referenced cell "i16" is populated with a "No" and formatted to text.
It was formatted as date and I thought maybe that was messing it up, but
after changing it to text and general it still would not fire on opening.

I had been setting the scroll area by running a macro, but decided to
include it in the workbook open, I thought it would handle it better and keep
the rest of the module cleaner.

If you see the obvious problem with this please let me know, I have stared
at it for hours and cannot see the problem. If you need the whole module
code I have pieced together, I am more than happy to paste the whole ugly
thing out here for you to review to see if I am running contradictory code
somewhere else in my procedures.

Any help or ideas on how to fix this or change it to make it work correctly
will be greatly appreciated. I am getting better at Macros and where to
place the code, but am still green when it comes to all things VB, so don't
assume I know too much.

Thanks,

Martin

Sorry for the long posting :)
 
A

anduare2

Disregard this post, I have finally figured it out. I am stupid. I was so
used to setting the scroll area with an on/off macro that when I moved it to
the workbook open, I forgot that I actually needed to close and then open the
workbook again for the lock / unlock to take effect. User error, told you
all I was green. I had it in my mind that it should be a workbook dynamic
type function.

Sorry
 

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

Top