Eat to live, and not live to eat. -Benjamin Franklin
〓いろんなものの置き場です。〓
純志のページ 更新日   


Word でマクロを使う

Ⅰ. マクロを使うための準備

  1. Word を起動
  2. [オプション] - [リボンのユーザー設定] - [「開発」にチェック]
    word01
  3. これでワードのメニューに「開発」が追加されます
    word02
  4. [セキュリティーセンター] - [セキュリティセンターの設定] - [マクロの設定]
    word03
  5. これで準備は完了です。次にマクロを記録します

Ⅱ. マクロを記録する

  1. [開発] のメニュー ※Ⅰ. 4.[セキュリティセンター] は [マクロのセキュリティ] からでもOK
    word04
  2. [マクロの記録]を選択すると下のダイアログになります ※今回はこれは使いません
    word05
  3. [Visual Basic]を選択すると下のダイアログになります
    word06
  4. [Visual Basic] - [挿入] - [標準モジュール] を選んでペースト
    word07
  5. 大量のワード文書をテキスト文書に変換するマクロです
    Sub docx2txtマクロ()
    '
    ' docx2txt Macro
    '
    '
    Dim wordFile As String, msg As String, txtFileName As String, hoge As String
    wordFile = Dir("C:\before_docx\*.docx")
    Do While wordFile <> ""
        txtFileName = "C:\convert_txt\" & Replace(wordFile, ".docx", ".txt")
        wordFile = "C:\before_docx\" & wordFile
        Documents.Open wordFile
        Documents(wordFile).Activate
        ActiveDocument.SaveAs2 FileName:=txtFileName, FileFormat:=wdFormatDOSTextLineBreaks
        ActiveDocument.Close
        msg = msg & txtFileName & vbCrLf
        wordFile = Dir()
    Loop
    MsgBox msg
    
    End Sub
    
  6. マクロを実行するときは、[開発] - [マクロ] から選択して実行
    word08
  7. docx2txtマクロ を選択して実行すると下のようになります。
    word文書(変換前)をtext文書(変換後)に一括変換
    word09
  8. 最後にすべてのテキストファイルを1ファイルにまとめます
    コマンドから copy /b C:\conver_txt\*.txt C:\all.txt


PageTop▲

Copyright © 2010 "Junshi Toyoda, Okinawa Japan"