网站建议:179001057@qq.com

使用VBA操作word

技术2022-05-12  5

1.引用Microsoft word 11.0 Object Library

2.下面代码可以打开并读取word文档。 

Dim Wdapp As Word.ApplicationDim WdDocument As Word.DocumentSet Wdapp = New Word.Application

// 当前文件路径

strFilePath = ActiveWorkbook.PathstrSearchFilesPath = strFilePath & "/*.doc"

// 取得所有的.doc 文档

strFileName = Dir(strSearchFilesPath)    Do While Trim(strFileName) <> ""                        // open word file            Set WdDocument = Wdapp.Documents.Open(strFilePath & "/" & strFileName)

           // 可视状态            Wdapp.Visible = False            // 如果word内部有表格,可以这样读取            writer = WdDocument.Tables(1).Cell(4, 4).Range.Text           。。。

           // 别忘了关闭

            WdDocument.Close

 

        // 下一个文件        strFileName = Dir    Loop


最新回复(0)