Blake 7,
Sorry I didn't get back to this thread sooner. In the .xla file, in the ThisWorkbook event module, you can use the following to create a button:
Private Sub Workbook_AddinInstall()
On Error Resume Next
'First thing the code does is remove the button if it hasn't been removed already
Application.CommandBars("Worksheet Menu Bar").Controls("MyMacro").Delete
'The above line results in an error if it has already been removed
'So this On Error Resume Next ignores if there's an error and just resumes starting below
Set MyMacro = Application.CommandBars("Worksheet Menu Bar").Controls.Add
With MyMacro
.Caption = "My Macro Button Name"
.Style = msoButtonCaption
.OnAction = "MyMacro" 'In your case this would be "move"
End With
End Sub
Of course, only having one-way functionality gives your addin a bad image. So you can use the AddinUninstall event to remove your button so that uninstallation is seamless and painless for the end user:
Private Sub Workbook_AddinUninstall()
On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("MyMacro").Delete
End Sub
Alternately, instead of using a button they press, you could simply put in a line to assign your add-in macro to a keyboard shortcut. This method doesn't require either of the above, but without the button its not apparent how to get the macro to run. So the following is only recommended if you're the one using it, not others:
Private Sub Workbook_Open()
On Error Resume Next
Application.OnKey "^{e}", "MyMacro" 'Assigns the macro to keyboard shortcut ctrl+e
End Sub
Hope that helps,
~tigeravatar
Bookmarks