選択した範囲を黒枠で囲み、一行目を黒地白抜きのタイトルにする【素人 Word マクロ】
Microsoft officeのWordVBAでマクロを組みましたので公開します。
インターネットで検索したり、マクロの記録機能を使ったり、AIに考えてもらったりしたのを組み合わせだけなので、上手くはないですが、一応動くはずです。
office2021です。
必ず、元データのバックアップを取ってから実行してください。
素人の作ったものなので、信用しすぎないでください。
[仕様]
選択した範囲を四角で囲み、一行目をセクションタイトルにします。
[コード]
Sub セクション加工()
Dim selectedRange As Range
Set selectedRange = Selection.Range
' 段落の背景を用いて選択範囲を四角で囲む
With selectedRange
.ParagraphFormat.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
.ParagraphFormat.Borders(wdBorderTop).LineWidth = wdLineWidth075pt
.ParagraphFormat.Borders(wdBorderTop).Color = wdColorBlack
.ParagraphFormat.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
.ParagraphFormat.Borders(wdBorderBottom).LineWidth = wdLineWidth075pt
.ParagraphFormat.Borders(wdBorderBottom).Color = wdColorBlack
.ParagraphFormat.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
.ParagraphFormat.Borders(wdBorderLeft).LineWidth = wdLineWidth075pt
.ParagraphFormat.Borders(wdBorderLeft).Color = wdColorBlack
.ParagraphFormat.Borders(wdBorderRight).LineStyle = wdLineStyleSingle
.ParagraphFormat.Borders(wdBorderRight).LineWidth = wdLineWidth075pt
.ParagraphFormat.Borders(wdBorderRight).Color = wdColorBlack
' 背景を設定
.Shading.BackgroundPatternColor = wdColorWhite
End With
' 1行目を黒地白抜きの背景で中央揃えにする
Dim firstParagraph As Range
Set firstParagraph = selectedRange.Paragraphs(1).Range
With firstParagraph
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Font.Size = 16
.Font.Color = wdColorWhite
.Shading.BackgroundPatternColor = wdColorBlack
End With
End Sub