PDA

View Full Version : Word VBA - Insert Horizontal Line



Marmalade
07-06-2016, 04:46 AM
Hi there,
I would like to use word VBA to add a horizontal line similar to those in which are created when you autocorrect &&&, ___ etc. (Sorry, cannot post links)
However, I can't find a satisfactory method.

I found .AddHorizontalLineStandard, which might do, but I don't particularly like the formatting and can't get it to simply add the line wherever the current selection is.

I thought maybe typing, for example, &&& or ### and somehow having it trigger autocorrect on the selection could work but have no idea how I'd do that...

Thanks in advance,

Lady Marmalade

gmayor
07-06-2016, 07:37 AM
Autocorrect enters a border so you could use

With Selection.ParagraphFormat
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
.Color = wdColorAutomatic
End With
End With