Loop through all Word Files in Directory

后端 未结 3 765
时光说笑
时光说笑 2021-01-01 01:08

I have the following code:

Sub WordtoTxtwLB()
\'
\' WordtoTxtwLB Macro
\'
\'
Dim fileName As String
myFileName = ActiveDocument.Name

ActiveDocument.SaveAs2          


        
3条回答
  •  旧巷少年郎
    2021-01-01 01:50

    To edit all the word documents in a directory I built this simple subroutine.

    The subRoutine loops through the directory and opens each *.doc file it finds. Then on the open document file it calls the second subRoutine. After the second subRoutine is finished the document is saved and then closed.

    Sub DoVBRoutineNow()
    Dim file
    Dim path As String
    
    
    path = "C:\Documents and Settings\userName\My Documents\myWorkFolder\"
    
    file = Dir(path & "*.doc")
    Do While file <> ""
    Documents.Open FileName:=path & file
    
    Call secondSubRoutine
    
    ActiveDocument.Save
    ActiveDocument.Close
    
    file = Dir()
    Loop
    End Sub
    

    ~~~~~~

提交回复
热议问题