1、1.遍历所有已打开的word文档For Each docOpened In Documents …… Next docOpened2.Word将目录下所有文档转换为txt,并删除原文档Sub 目录下doc转txt() '目录下所有word文档转为txt,并删除word文档 '保存在原目录 '遍历所有文件夹,把带路径的文件名存入字典 On Error Resume Next Dim Path As String, t 'Path为路径,t用于计算程序执行花费的时间
2、 Set objshell = CreateObject("Shell.Application") Set objfolder = objshell.BrowseForFolder(0, "选择文件夹", 0, 0) If Not objfolder Is Nothing Then Path = objfolder.self.Path & "" Set objfolder = Nothing Set objshell = Nothing '创建字典用于存储
3、路径和文件名 Dim DicPath, DicFile, i As Integer, Ke, ContentName As String, FileName As String, MsgTxt Set DicPath = CreateObject("Scripting.Dictionary") Set DicFile = CreateObject("Scripting.Dictionary") DicPath.Add Path, "" i = 0 '存所有
4、路径 Do While i < DicPath.count Ke = DicPath.keys ContentName = Dir(Ke(i), vbDirectory) Do While ContentName <> "" '若有子文件夹,则添加 '跳过当前的目录及上层目录 If ContentName <> "." And ContentName <> ".." Then
5、 If GetAttr(Ke(i) & ContentName) = vbDirectory Then DicPath.Add (Ke(i) & ContentName & ""), "" End If End If ContentName = Dir Loop i = i + 1 Loop
6、 '存所有doc文件名 For Each Ke In DicPath.keys FileName = Dir(Ke & "*.doc") Do While FileName <> "" DicFile.Add (Ke & FileName), "" FileName = Dir Loop Next Ke '打开文件 Application.DisplayAlert
7、s = wdAlertsNone Dim myDoc For Each Ke In DicFile.keys Set myDoc = Documents.Open(Ke) '原路径另存为TXT ActiveDocument.SaveAs2 FileName:=myDoc.Path & "" & Left(myDoc.Name, InStrRev(myDoc.Name, ".") - 1) & ".txt", FileFormat:=wdFo
8、rmatText '处理完成后关闭并删除原word文档 ActiveDocument.Close Kill Ke Next Ke MsgBox "Done!" End Sub 1.获取网页源代码Dim httpRequest As Object Set httpReque