运行 宏时出现错误 4605 "this method or property is not available because there is a memory or disk error"
Error 4605 "this method or property is not available because there is a memory or disk error" upon running Macro
这是 MS-Word 宏。
它会产生此错误:
Error 4605 "this method or property is not available because there is
a memory or disk problem
' 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 process 的内存消耗增加了近 5 倍。不过,我仍然有足够的 RAM。我 运行 Windows 8.1 x86_64 上的正版 Word 2013。为什么会发生这种情况,我该如何解决这个错误?
在这种情况下,显然是撤消堆栈堵塞了。
简单修复:修改代码如下:
'...
'...
Next
If bDel = True Then .Delete
Doc.UndoClear
End If
End With
从 File/options/customized 功能区启用开发人员菜单。
然后按 ALT-F11 并将此代码粘贴到那里。
按 F5。
Sub Removedenter code hereNonDefaultStyles()
Dim CurrentStyleInLoop As Style
For Each CurrentStyleInLoop In ActiveDocument.Styles
If Not CurrentStyleInLoop.BuiltIn Then
CurrentStyleInLoop.Delete
End If
Next CurrentStyleInLoop
End Sub
这是 MS-Word 宏。 它会产生此错误:
Error 4605 "this method or property is not available because there is a memory or disk problem
' 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 process 的内存消耗增加了近 5 倍。不过,我仍然有足够的 RAM。我 运行 Windows 8.1 x86_64 上的正版 Word 2013。为什么会发生这种情况,我该如何解决这个错误?
在这种情况下,显然是撤消堆栈堵塞了。
简单修复:修改代码如下:
'...
'...
Next
If bDel = True Then .Delete
Doc.UndoClear
End If
End With
从 File/options/customized 功能区启用开发人员菜单。
然后按 ALT-F11 并将此代码粘贴到那里。 按 F5。
Sub Removedenter code hereNonDefaultStyles()
Dim CurrentStyleInLoop As Style
For Each CurrentStyleInLoop In ActiveDocument.Styles
If Not CurrentStyleInLoop.BuiltIn Then
CurrentStyleInLoop.Delete
End If
Next CurrentStyleInLoop
End Sub