0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WORD VBA テンプレート内の文字列置換マクロ

Last updated at Posted at 2018-12-17

#ワード内の文章を置換

Sub mojiretuhenkan()
    
    Dim rbook As Object, rrow As Object
    Set rbook = GetObject(ActiveDocument.Path & "\置換テーブル.xlsx")
    
    With ActiveDocument.Content.Find
        For Each rrow In rbook.Worksheets(1).Range("検索置換セット").Rows
            If rrow.Cells(1).Value = "" Then Exit For
            
            .Text = rrow.Cells(1).Value
            .Replacement.Text = rrow.Cells(2).Value
            .Execute Replace:=wdReplaceAll
            
        Next rrow
    End With 'ActiveDocument.Content.Find
    
    rbook.Application.Quit
    Set rbook = Nothing
    
End Sub
0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?