这是 MS-Word 宏。它会产生此错误:
错误 4605“此方法或属性不可用,因为存在内存或磁盘问题
' Word script to remove all unused styles in the document
Sub DeleteUnusedStyles()
Dim Doc As Document, bDel As Boolean
Dim Rng As Range, StlNm As String, i As Long
Application.ScreenUpdating = False
Set Doc = ActiveDocument
With Doc
For i = .Styles.Count To 1 Step -1
With .Styles(i)
If .BuiltIn = False Then
bDel = True: StlNm = .NameLocal
For Each Rng In Doc.StoryRanges
With Rng
With .Find
.ClearFormatting
.Format = True
.Style = StlNm
.Execute
End With
If .Find.Found = True Then
bDel = False
Exit For
End If
End With
Next
If bDel = True Then .Delete
End If
End With
Next
End With
Application.ScreenUpdating = True
End Sub
它应该从 word 文档中删除所有未使用的样式。我在互联网上找到并测试了其他 3 个应该做同样事情的宏,但最后出现了同样的错误。Word 文档暂停了大约 5 分钟(它是 100 页的严重格式化的文档),然后它吐出这个错误。在错误出现之前,我可以看到 word 进程的内存消耗增加了近 5 倍。我仍然有足够的内存。我在 Windows 8.1 x86_64 上运行正版 Word 2013。为什么会发生这种情况,我该如何解决这个错误?