word批量转txt,付费的东东,先存着

2021-08-09 20:26:15  阅读 241 次 评论 0 条

以下代码测试运行出错:


Public Declare Function SHBrowseForFolder Lib "shell32.dll" Alias

"SHBrowseForFolderA" (lpBrowseInfo As FolderInfor) As Long

Public Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias

"SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long

Public Type FolderInfor

hOwner As Long

pidlRoot As Long

pszDisplayName As String

lpszTitle As String

ulFlags As Long

lpfn As Long

lParam As Long

iImage As Long

End Type


Public Function BrowDir() As String

Dim iFolder As FolderInfor

Dim pidl As Long, Flag As Long, iPath As String, Pos As Integer     pidl = SHBrowseForFolder(iFolder)

iPath = Space$(512)

Flag = SHGetPathFromIDList(ByVal pidl, ByVal iPath)

If Flag Then

Pos = InStr(iPath, Chr$(0))

BrowDir = Left(iPath, Pos - 1)

End If

End Function


Sub BatDocToTxt()

Dim InPath As String, Filename As String, OutPath As String

rc = MsgBox("本功能为将指定文件夹中的所有doc文档转换为txt文件。" + vbCrLf + "已准备就绪可继续?", vbInformation + vbYesNo + vbDefaultButton2, "消息")

If rc = vbNo Then Exit Sub

MsgBox "请指定待处理的文档所在的目录。", vbInformation, "消息"   InPath = BrowDir

If InPath = "" Then Exit Sub

MsgBox "请指定待转换后的txt文件的输出目录。" + vbCrLf + "默认为待处理的目录。", vbInformation, "消息"

OutPath = BrowDir

If OutPath = "" Then OutPath = InPath

MsgBox "即将进行转换,并未死机,请耐心等候完成通知!", vbInformation, "消息"

Application.Visible = False

Application.DisplayAlerts = wdAlertsNone

Filename = Dir(InPath & "\*.doc")

Do Until Filename = ""

On Error Resume Next

Documents.Open InPath & "\" & Filename

If Err.Number = 0 Then ActiveDocument.SaveAs OutPath & "\" & Left(Filename, Len(Filename) - 3) & "txt", 2

On Error Resume Next

ActiveDocument.Close

Filename = Dir()

Loop

rc = MsgBox("转换完毕!要打开输出目录吗?", vbInformation + vbYesNo, "消息")

If rc = vbYes Then Shell "explorer.exe " + OutPath, vbMaximizedFocus  Application.Visible = True

Application.DisplayAlerts = wdAlertsAll

End Sub

WPS达师专注于免费分享WPS Office使用教程、PPT、word模板及办公常用软件等资源,欢迎大家收藏和分享本站。
WPS表格数据付费处理请加QQ:3247742

发表评论


表情

还没有留言,还不快点抢沙发?