PDA

View Full Version : [SOLVED:] How can I open the Modify Style dialog box in Word Visual Basic?



BobSundquist
12-23-2015, 03:50 PM
Application.Dialogs(?).Show

gmayor
12-25-2015, 09:55 PM
It appears that you can't, but as you are presumably programming styles in VBA, iut shouldn't be necessary. You can simply address the style directly, and if you need to get a value from a user, then employ an input box or a userform.

gmaxey
12-26-2015, 06:41 AM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
MsgBox "One would think that wdDialogEditStyle would be the ticket. It isn't. This will work though:"
Application.Dialogs(1347).Show
lbl_Exit:
Exit Sub
End Sub

BobSundquist
12-28-2015, 07:32 AM
Thanks, that works. You must be very smart. I never would have guessed 1347.
Can you tell me the purpose of the lbl_Exit: label in your subprogram?

gmaxey
12-28-2015, 09:31 AM
Bob,

In this case no purpose really. It is just my unorthodox coding style. If I had an error handler it might look like this:

Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
On Error GoTo Err_Handler
MsgBox "One would think that wdDialogEditStyle would be the ticket. It isn't. This will work though:"
Application.Dialogs(1347).Show
lbl_Exit:
Exit Sub
Err_Handler:
Msgbox Err.Number
Resume lbl_Exit
End Sub

rtwoodward
05-28-2019, 11:40 AM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
MsgBox "One would think that wdDialogEditStyle would be the ticket. It isn't. This will work though:"
Application.Dialogs(1347).Show
lbl_Exit:
Exit Sub
End Sub


The dialog 1347 works, but I'm finding that when I try to change formats other than those that appear on the first page (e.g. paragraph formatting) it does not save. Any suggestions?
Thanks

StephenC
02-21-2020, 09:51 AM
This is a clumsy method, but it works, at least if run as a macro from within the text of the document, e.g. using a custom keyboard shortcut. (It depends on keyboard shortcut Alt+' being set to bring up the "Style" dialog box - I can't remember whether that was something I set up ages ago, or is the default - but the %' in each SendKeys statement could be modified to match whatever the shortcut is for you.)

If ActiveDocument.Styles(Selection.Style).BuiltIn Then
SendKeys "%'{tab}{tab}{enter}"
Else
SendKeys "%'{tab}{tab}{tab}{enter}"
End If