PC Review


Reply
Thread Tools Rate Thread

Assign kbd shortcut to a macro using vba

 
 
=?Utf-8?B?RGVhbg==?=
Guest
Posts: n/a
 
      5th Apr 2007
I have copied a macro from one (master) spreadsheet to another using the code
below. But when I open the spreadsheet which the code has been copied into up
the kbd shortcut which I had given it is lost. The code works if I go alt+F8
| run; and I can re-assign the kbd shortcut through options but I want it to
be there automatically. Is there any way to do this when I copy the code
across?
Thanks, Dean.

'copy macro to validated wookbook
Dim FName As String
With Workbooks("TEAMS_Master.xls")
FName = .Path & "\code.txt"
.VBProject.VBComponents("Module9").Export FName
End With
Workbooks("CBev.xls").VBProject.VBComponents.Import FName

'code I am copying to new workbook
Sub Macro_t()
'
' Macro_t Macro
' Macro recorded 05/04/2007 by Dean
'
' Keyboard Shortcut: Ctrl+t
'
Range("Y2").Select
Selection.AutoFilter
Selection.AutoFilter Field:=25, Criteria1:=">0", Operator:=xlAnd
Range("A1").Select
End Sub
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      6th Apr 2007
Dean,

try this:

Application.MacroOptions Macro:="Macro_t", ShortcutKey:="t"


--
Hope that helps.

Vergel Adriano


"Dean" wrote:

> I have copied a macro from one (master) spreadsheet to another using the code
> below. But when I open the spreadsheet which the code has been copied into up
> the kbd shortcut which I had given it is lost. The code works if I go alt+F8
> | run; and I can re-assign the kbd shortcut through options but I want it to
> be there automatically. Is there any way to do this when I copy the code
> across?
> Thanks, Dean.
>
> 'copy macro to validated wookbook
> Dim FName As String
> With Workbooks("TEAMS_Master.xls")
> FName = .Path & "\code.txt"
> .VBProject.VBComponents("Module9").Export FName
> End With
> Workbooks("CBev.xls").VBProject.VBComponents.Import FName
>
> 'code I am copying to new workbook
> Sub Macro_t()
> '
> ' Macro_t Macro
> ' Macro recorded 05/04/2007 by Dean
> '
> ' Keyboard Shortcut: Ctrl+t
> '
> Range("Y2").Select
> Selection.AutoFilter
> Selection.AutoFilter Field:=25, Criteria1:=">0", Operator:=xlAnd
> Range("A1").Select
> End Sub

 
Reply With Quote
 
=?Utf-8?B?RGVhbg==?=
Guest
Posts: n/a
 
      6th Apr 2007
Thanks Vergel, that works great.

Cheers, Dean

"Vergel Adriano" wrote:

> Dean,
>
> try this:
>
> Application.MacroOptions Macro:="Macro_t", ShortcutKey:="t"
>
>
> --
> Hope that helps.
>
> Vergel Adriano
>
>
> "Dean" wrote:
>
> > I have copied a macro from one (master) spreadsheet to another using the code
> > below. But when I open the spreadsheet which the code has been copied into up
> > the kbd shortcut which I had given it is lost. The code works if I go alt+F8
> > | run; and I can re-assign the kbd shortcut through options but I want it to
> > be there automatically. Is there any way to do this when I copy the code
> > across?
> > Thanks, Dean.
> >
> > 'copy macro to validated wookbook
> > Dim FName As String
> > With Workbooks("TEAMS_Master.xls")
> > FName = .Path & "\code.txt"
> > .VBProject.VBComponents("Module9").Export FName
> > End With
> > Workbooks("CBev.xls").VBProject.VBComponents.Import FName
> >
> > 'code I am copying to new workbook
> > Sub Macro_t()
> > '
> > ' Macro_t Macro
> > ' Macro recorded 05/04/2007 by Dean
> > '
> > ' Keyboard Shortcut: Ctrl+t
> > '
> > Range("Y2").Select
> > Selection.AutoFilter
> > Selection.AutoFilter Field:=25, Criteria1:=">0", Operator:=xlAnd
> > Range("A1").Select
> > End Sub

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assign shortcut key to existing Excel Macro PatCos Microsoft Excel Programming 1 12th Jun 2008 12:00 AM
assign shortcut to macro Gary Keramidas Microsoft Excel Programming 3 15th Dec 2006 03:08 PM
Is there a way to assign a shortcut key to an existing macro? =?Utf-8?B?SmVzc2VCcm91c3NhcmQ=?= Microsoft Access Macros 1 27th Jul 2006 12:11 AM
assign shortcut to macro in addin =?Utf-8?B?UGF0cmljaw==?= Microsoft Excel Programming 0 23rd Nov 2004 03:01 PM
Re: How can Assign a macro to a particular Form with a Shortcut Glen Appleton Microsoft Access Form Coding 0 15th Sep 2003 07:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:48 PM.