Add a button to a macro

T

TomBP

At the moment I use a shortcut-key for a macro. Now what I would like is
a person to click a button which activates the macro instead of them
using the shortcut-key.


Code:
--------------------
Sub SearchAndOpen()
'
' SearchAndOpen Macro
' Macro recorded 7/07/2006 by Tom Fack
'
' Keyboard Shortcut: Ctrl+r
'

Dim s1 As String, bk As Workbook, bk1 As Workbook
s1 = "C:\Documents and Settings\" & _
"fackt0\Desktop\Excel Probleem\Shipments\"

Set bk = ActiveWorkbook
If Dir(s1 & Range("J5").Text & ".xls") <> "" Then
Set bk1 = Workbooks.Open(s1 & Range("J5").Text & ".xls")
bk.Activate
Else
MsgBox "workbook not found"
End If

End Sub
 
K

Ken Johnson

Hi Tom,

I like to use a button from the Forms toolbar.

Go View|Toolbars|Forms,then click on the little button icon on the
Forms Toolbar then click on your worksheet. The "Assign Macro" dialog
that appears should have your macro's name in the list of macros. You
can either double click its name or single click it then click the OK
button. After doing that your macro should run when you click the
button. To make any changes to the button's appearance just right click
it first.

I prefer this button to the Command Button from the Control Toolbar
because it works on PCs and Macs.

Ken Johnson
 
T

TomBP

Thx Ken. I thought it would be a whole lot of code but its as easy as
getting up in the morning for work ;)
 
T

TomBP

Thx Ken. I thought it would be a whole lot of code but its as easy as
getting up in the morning for work ;)
 
T

TomBP

Thx Ken. I thought it would be a whole lot of code but its as easy as
getting up in the morning for work ;)
 
T

TomBP

Thx Ken. I thought it would be a whole lot of code but its as easy as
getting up in the morning for work ;)
 
K

Ken Johnson

Hi Tom,

At the moment I wouldn't know about that, I'm currently on holiday:)

Thanks for the feedback.

Ken Johnson
 

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