文書を1行ずつ表示する【素人 Word マクロ】

Microsoft officeのWordVBAでマクロを組みましたので公開します。
インターネットで検索したり、マクロの記録機能を使ったりしたのを組み合わせだけなので、上手くはないですが、一応動くはずです。
office2021です。
必ず、元データのバックアップを取ってから実行してください。
素人の作ったものなので、信用しすぎないでください。

[仕様]
1行目からメッセージボックスに表示します。
OKを押すと次の行へ進みます。
キャンセルを押すと終了します。

[コード]

Sub Word文書の文字列を一行ずつ取得する()
    Dim pg As Page
    Dim rc As Rectangle
    Dim ln As Line

    Dim continueProcessing As VbMsgBoxResult
    continueProcessing = vbOK

    With ActiveWindow
        .View.Type = wdPrintView
        For Each pg In .ActivePane.Pages
            For Each rc In pg.Rectangles
                If continueProcessing = vbCancel Then Exit Sub ' Check if we should cancel
                If rc.RectangleType = wdTextRectangle Then
                    For Each ln In rc.Lines
                        If continueProcessing = vbCancel Then Exit Sub ' Check if we should cancel
                        continueProcessing = MsgBox(ln.Range.Text, vbOKCancel)
                        If continueProcessing = vbCancel Then Exit Sub ' Check if we should cancel
                    Next ln
                End If
            Next rc
        Next pg
    End With
End Sub

この記事が気に入ったらサポートをしてみませんか?