How can I write a macro to assign a shortcut to another macro?

I’m wondering if it is possible to create a macro which itself assigns a list of existing macros to another existing lists of shortscuts? Macro recorder was no help. I know how to bind a macro to a shortcut over the menue: Tools → Customize → Keyboard …
But writing a macro for this task, I even don’t know where to start …
Any ideas?

Seems to me that you should start by reading this page

JohnSun, thank you, I read it, hmmmm, still no improvement …

Some years ago I wrote in VBA this to assign my macros to a shortcut list

Sub AssignShortCuts()

m = Array(“macro1”, “macro2”, “macro3”)

s = Array(“a”, “b”, “c”)

With Application

For i = 0 To UBound(m)

.MacroOptions Macro:=m(i), HasShortcutKey:=True, ShortcutKey:=si)


End With

End Sub

Hello @Ulli_Wue, you could use the following code to assign a keyboard shortcut to a macro:

Sub Main()
	REM Set your Macro URL and your Keyboard Shortcut here:
	Dim strCommandURL$, oKeyEvent
	strCommandURL = ""
	oKeyEvent = CreateKeyEvent( 2, )		REM Ctrl-J
	SetCommandShortcut( oKeyEvent, strCommandURL )
	'RemoveCommandShortcut( strCommandURL )
End Sub

Function getShortCutManager()
REM Return the ShortCutManager for the current Office Module.
	Dim oModuleManager As Object, oModuleIdent
	Dim oModuleConfigManager As Object, oModuleConfigManagerSupplier As Object
	oModuleManager = createUnoService( "" )
	oModuleIdent = oModuleManager.identify( ThisComponent )
	oModuleConfigManagerSupplier = createUnoService( "" )
	oModuleConfigManager = oModuleConfigManagerSupplier.getUIConfigurationManager( oModuleIdent )
	getShortCutManager = oModuleConfigManager.getShortCutManager()
End Function

Sub SetCommandShortcut( oKeyEvent, strCommandURL as String )
REM Adapted from code by Paolo Mantovani.
REM Connects a Keyboard Shortcut to a certain Command, such as a macro or UNO dispatch.
REM   <oKeyEvent>: representing the Keyboard Shortcut for this Command.
REM   <strCommandURL>:	the Command to which the Keyboard Shortcut will be attached.
REM Example call:
REM	strCommandURL = ""
REM oKeyEvent = CreateKeyEvent( 2, )		REM Ctrl-J
REM	SetCommandShortcut( oKeyEvent, strCommandURL )
	Dim oShortCutManager As Object
	oShortCutManager = getShortCutManager()
	oShortCutManager.setKeyEvent( oKeyEvent, strCommandURL )
End Sub

Sub RemoveCommandShortcut( strCommandURL as String )
REM Removes all the Keyboard Shortcut(s) associated with the specified Command.
REM <strCommandURL>: a Command that has one or more Keyboard Shortcuts to be removed from it.
	Dim oShortCutManager As Object
	oShortCutManager = getShortCutManager()
	oShortCutManager.removeCommandFromAllKeyEvents( strCommandURL )
End Sub

Function CreateKeyEvent( iModifiers as Integer, iKeyCode as Integer ) As
REM Construct and return a KeyEvent structure.
	Dim aKeyEvent As New
	aKeyEvent.Modifiers = iModifiers
	aKeyEvent.KeyCode = iKeyCode
	CreateKeyEvent = aKeyEvent
End Function