見出し画像

【WordVBA】覚え書きを14項目列挙

長年ExcelのVBAをやっていたせいか、WordのVBAは思うようにできなくて結構手こずっています。簡単なコードのみですが、備忘録として残しておきます。

環境設定

'文書全体のスタイルを標準に一括変更(太字も全部クリア)
ActiveDocument.Paragraphs.Style = wdStyleNormal
'文書全体の蛍光ペンを解除
ActiveDocument.Range.HighlightColorIndex = wdNoHighlight
'ページ設定
With ActiveDocument.PageSetup
    .LinesPage = 38 '行数
    .LayoutMode = wdLayoutModeLineGrid '「行数だけを指定する」に設定
End With
'余白を「やや狭い」に変更
With Selection.PageSetup
    .TopMargin = MillimetersToPoints(25.4)
    .BottomMargin = MillimetersToPoints(25.4)
    .LeftMargin = MillimetersToPoints(19.05)
    .RightMargin = MillimetersToPoints(19.05)
End With
'表示倍率の変更
ActiveWindow.View.Zoom = 140
'ウィンドウの位置調整
With Application
    .Resize Width:=1150, Height:=780
    .Move Left:=50, Top:=0
End With
'MS明朝の12ptに変更
Selection.WholeStory
Selection.Font.Name = "MS 明朝"
Selection.Font.Size = 12
 

編集

'改行する
Selection.TypeParagraph
'2行目を改行
ActiveDocument.Paragraphs(1).Range.InsertParagraphAfter
'1段落目を太字にする
ActiveDocument.Paragraphs(1).Range.Font.Bold = True
'1段落目の太字を解除
ActiveDocument.Paragraphs(1).Range.Font.Bold = False
'1行目を中央揃えにする
With ActiveDocument.Paragraphs(1).Range
    .ParagraphFormat.Alignment = wdAlignParagraphCenter
End With
'編集可に変更
Application.ActiveProtectedViewWindow.Edit
 

校閲関連

'文字数を表示
MsgBox ActiveDocument.Range.ComputeStatistics(wdStatisticWords) & " 字です。"
'文書スタイルを「通常の文(校正用)」に変更し、文章校正を再度実行
With ActiveDocument
    .ActiveWritingStyle(Application.Language) = "通常の文(校正用)"
     Application.ResetIgnoreAll        'スペルチェックで無視された語の一覧をクリア
    .SpellingChecked = False
    .GrammarChecked = False
End With
'変更履歴の記録開始
 ActiveDocument.TrackRevisions = True
'変更履歴の記録をオフ
 ActiveDocument.TrackRevisions = False
'仲室の吹き出しをオフ
ActiveWindow.View.RevisionsFilter.Reviewers("仲室").Visible = False
'仲室の吹き出しをオン
ActiveWindow.View.RevisionsFilter.Reviewers("仲室").Visible = True


もしよければ、サポートいただけますと幸いです。 執筆の資料代など、有効活用させていただきます……!