View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Papou Papou is offline
external usenet poster
 
Posts: 56
Default Button Selection OnAction property

Hi Grant
Replace
Selection.OnAction = "Call Go_To(""Sheet 1"")"

with
Go_To("Sheet1")

I would also suggest some slight amendment to your Go_To function :
'Replace Address with SheetName since Address is an existing expression in
VBA
Function Go_To(SheetName As String)
Sheets(SheetName).Select
Range("A1").Select
End Function

HTH
Cordially
Pascal

"Grant Reid" a écrit dans le message de
...
Hi

I have a function that I often call from within my code to take me to a
particular sheet.

Public Function Go_To(address As String)
Sheets(address).Select
Range("A1").Select
End Function

I now want to create a button that will call this function, and am at a

loss
as to how to do this. Can anyone help? Is it possible to do this?

Here is my code for the button

Sub Button
ActiveSheet.Buttons.Add(350, 0, 72, 72).Select
Selection.Name = "Go_To_Index"
Selection.OnAction = "Call Go_To(""Sheet 1"")" '<-----------Here is

my
problem
ActiveSheet.Shapes("Go_To_Index").Select
Selection.Characters.Text = "Go To Index"
With Selection.Characters(Start:=1, Length:=18).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.ReadingOrder = xlContext
.Orientation = xlHorizontal
.AutoSize = True
End With
End Sub


Many Thanks - Grant