PDA

View Full Version : Assigning shortcut key for word style



senthilkumar
12-19-2011, 09:54 PM
Hi All,

I am dynamically creating styles from text file in word document. I have created styles successfully. But I am not able to assign shortcut keys for created styles. I am creating style through function and I am passing StyleName and StyleType as arguments. I also need to pass Shortcut key for style. When I am doing this I am getting "Bad Parameter" error.

Below is the function.

Public Sub CreateStyle(sNewStyleName As String, isParaStyle As Boolean)
Dim ssKey As WdKey
ssKey = wdKeyA
If isParaStyle = True Then
With ActiveDocument
.Styles.Add Name:=sNewStyleName, Type:=wdStyleTypeParagraph
.Styles(sNewStyleName).AutomaticallyUpdate = False
KeyCode:=BuildKeyCode(ssKey, wdKeyControl, wdKeyShift, wdKeyAlt), KeyCategory:=wdKeyCategoryStyle, Command:=""
End With
Else
With ActiveDocument
.Styles.Add Name:=sNewStyleName, Type:=wdStyleTypeCharacter
KeyCode:=BuildKeyCode(ssKey, wdKeyControl, wdKeyShift, wdKeyAlt), KeyCategory:=wdKeyCategoryStyle, Command:=""
End With
End If
End Sub

Please help me to sort out.

Thanks,
Senthil. S :help