0
我正在搜索宏,该批打开.doc文件并将它们保存为.docx。我已经找到一个。现在我想删除所有文档中的任何突出显示(保留文本;以及执行更多清理操作)。当我添加一行(到我能猜到的最佳位置)时,它会连续运行而不会在最后一个文档之后停止。任何想法在哪里以及如何去修正它?Word宏,批量从.doc文件中删除高亮(并将其保存为.docx)
Sub batch_cleaner()
Dim strFilename As String
Dim strDocName As String
Dim strPath As String
Dim oDoc As Document
Dim fDialog As FileDialog
Dim intPos As Integer
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , "List Folder Contents"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
If Left(strPath, 1) = Chr(34) Then
strPath = Mid(strPath, 2, Len(strPath) - 2)
End If
strFilename = Dir$(strPath & "*.doc")
While Len(strFilename) <> 0
Set oDoc = Documents.Open(strPath & strFilename)
“在这里我想补充的东西
strDocName = ActiveDocument.FullName
intPos = InStrRev(strDocName, ".")
strDocName = Left(strDocName, intPos - 1)
strDocName = strDocName & ".docx"
oDoc.SaveAs FileName:=strDocName, _
FileFormat:=wdFormatDocumentDefault
oDoc.Close SaveChanges:=wdDoNotSaveChanges
strFilename = Dir$()
Wend
End Sub
而这个代码总是废墟它:
Selection.WholeStory
Selection.Range.HighlightColorIndex = wdNoHighlight
或枚举所有文件到一个数组中,然后循环该数组。 – ths 2014-09-03 23:54:36
我不认为这是8.3名称的问题。也许只是因为我正在处理文档,这就是为什么会创建隐藏的.doc文档。无论如何,我需要在最后使用.docx,所以你能否帮助我以某种方式修改我的宏,以便将结果存储到子文件夹中(对我来说这似乎是个好主意)? – matx 2014-09-04 21:41:59