How to show "New style" dialog using VBA

V

viter.alex

Can I do subject? I know about WordBasic.NewStyle but it isn't I want.
I want like this:
ActiveDocument.Styles.Add MyStyleName, wdStyleTypeCharacter
'And here show dialog to edit this just created style.
 
J

Jay Freedman

This isn't nearly as straightforward as it should be, because the
Modify Style dialog appears not to be a member of the Dialogs
collection. (I'd be happy if someone contradicts me on this point.)

The workaround is to apply the character style to the current
selection so that style will appear in the Style dialog, display the
Style dialog, and use the SendKeys function to "click" the Modify
button.

Dim MyStyle As Style

Set MyStyle = ActiveDocument.Styles.Add( _
MyStyleName, wdStyleTypeCharacter)
Selection.Style = MyStyle
SendKeys "%m"
Dialogs(wdDialogFormatStyle).Show
Selection.Font.Reset

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
V

viter.alex

Thank you, Jay. It works! I added 200 ms delay after SendKeys in order
to avoid typing "m" in the format style dialog

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)
Dim MyStyle As Style
Set MyStyle = ActiveDocument.Styles.Add( _
MyStyleName, wdStyleTypeCharacter)
Selection.Style = MyStyle
SendKeys "%m"
Sleep 200
Dialogs(wdDialogFormatStyle).Show
Selection.Font.Reset
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top