2

If you have look at these two captured images...

enter image description here

Basically, stepping into the next line should not change the selected tab as shown here. This is what happens if I click F5 from the VBA Editor to execute the sub

But when I actually run it using a linked command button which suppose to be doing the exactly same thing (photo shown down the thread). but what happens is this,

enter image description here

Stepping into the next line actually somehow changes the tab!

There is noting in the first break point line that tells excel to select another tab... why is this doing this.

if I run it using F8, actually this problems goes away.

UPDATED=============================================================

I come across some weird behaviour in the Excel VBA and can't explain why its doing it.

Sub run_simulation()   
    ActiveWorkbook.Worksheets("Run Simulation").Select
    ActiveSheet.CommandButton1.value = True
End Sub

This subroutine selects a sheets then simulates the clicking of a button 'CommandButton1'.

When I execute this from the play icon within the VBA Editor it runs fine but when I run this 'run_simulation' subroutine from a linked button on another sheet... like this

enter image description here

an error returns saying that the selected sheet "run_simulation" is protected and needs to be unprotected before proceeding... the thing is it unprotects the sheets automatically when the commandButton1 is clicked.

Cœur
  • 37,241
  • 25
  • 195
  • 267
lukieleetronic
  • 623
  • 7
  • 10
  • 23

1 Answers1

0

The Worksheet.Protect method has a little-used UserInterfaceOnly parameter.

From MSDN:

UserInterfaceOnly (optional) - True to protect the user interface, but not macros. If this argument is omitted, protection applies both to macros and to the user interface.

Set this to True when setting the worksheet protection and you will be able to manipulate the worksheet objects programmatically.