Stretchwickster
Programmer
Hi there,
On running a macro (originally written in Excel 2003) in Excel 2007 I get a "Run-time error '9': Subscript out of range" error which arises from the following code:
On further investigation it appears that the string value contained in Application.Caller is missing the last character and therefore an attempt is made to activate a sheet which doesn't exist. In Excel 2003, this last character is included and so the appropriate sheet is correctly activated.
I should explain that I use the following code to dynamically add a textbox (which, when clicked, calls the above GoToChart sub) to a worksheet to provide an easy means of navigating between a worksheet containing a table of data and a worksheet charting that tabular data.
Any solutions would be gratefully received.
Clive
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
On running a macro (originally written in Excel 2003) in Excel 2007 I get a "Run-time error '9': Subscript out of range" error which arises from the following code:
Code:
Public Sub GoToChart()
' check which text box button called the macro and activate appropriate sheet
If TypeName(Application.Caller) = "String" Then
Sheets(Application.Caller).Activate [COLOR=red]'this line triggers error[/color]
End If
End Sub
I should explain that I use the following code to dynamically add a textbox (which, when clicked, calls the above GoToChart sub) to a worksheet to provide an easy means of navigating between a worksheet containing a table of data and a worksheet charting that tabular data.
Code:
ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, ALeft, ATop, 180, 18).Select
With Selection
.Name = ActiveChart.Name
.Characters.Text = "Go to Percentage Chart " & chartCounter
.OnAction = "GoToChart"
End With
Clive
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096