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