Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Assign kbd shortcut to a macro using vba

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.Impor t 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Assign kbd shortcut to a macro using vba

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.Impor t 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Assign kbd shortcut to a macro using vba

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.Impor t 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assign shortcut keys droper Excel Discussion (Misc queries) 2 May 14th 07 09:59 AM
assign shortcut to macro Gary Keramidas Excel Programming 3 December 15th 06 03:08 PM
Assign ShortCut-key To Toggle VBA-toolbar? SIGE Excel Programming 4 April 19th 05 04:45 PM
assign a symbol to a shortcut key Martin Hennegriff Excel Discussion (Misc queries) 1 March 10th 05 09:03 PM
not getting the "assign macro" shortcut JC Home[_2_] Excel Programming 3 October 2nd 04 11:07 PM


All times are GMT +1. The time now is 08:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"