Forum Discussion
Hakana
Mar 28, 2026Copper Contributor
Word VBA, Unreachable table style setting?
I've noticed something that may be a missing feature in the Word VBA Object model. Styles in word can be of different kinds set by the WdStyleType when adding a style via expression.Add (Name, Type)...
Hakana
Apr 07, 2026Copper Contributor
While I still would call it a "bug" in that the object model does not include a way to reach the setting I sought to control, I have found a workaround.
It lets VBA "makes the change via UI" by sending a set of "key-presses" just before opening up part of the UI. Not the prettiest of solutions but still...
Sub SetHeaderRepeat(sty As String)
' This is a strange function. It is necessary since I have found no way of
' reaching the "Repeat as header row" setting in a Table Style using VBA.
' It can only be made through UI. The trick is to send a number of
' keyboard commands and then open a UI Dilogue. This makes word
' execute the Keyboard strokes.( % represents key 'ALT' and ~ is Enter.)
Dim dia As Dialog
Set dia = Dialogs(WdWordDialog.wdDialogFormatStyle)
SendKeys "%S"
SendKeys sty
SendKeys "%M"
SendKeys "%o"
SendKeys "~"
SendKeys "%h"
SendKeys "~~"
SendKeys "{Esc}"
With dia
.Show
End With
End Sub