请求的对象不可用 [英] Requested Object is not Available

查看:113
本文介绍了请求的对象不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Mac Word文档上运行以下宏:

I'm trying to run the following macro on a Mac Word document:

Sub AcceptDeletion()
    Dim oChange As Revision
    For Each oChange In ActiveDocument.Revisions
        With oChange
            If .Type = wdRevisionDelete Then
                .Accept
            End If
        End With
    Next oChange
End Sub

它在以下问题中发布:要接受的Microsoft Word VBA脚本所有删除?

It is posted in this question: Microsoft Word VBA script to accept all deletions?

它清除了几个已删除的修订,但是在这里失败了:

It cleared several deleted revisions but then failed here:

If .Type = wdRevisionDelete Then

...具有请求的对象不可用"的信息;运行时错误(5852).

...with "Requested Object is not Available" run-time error (5852).

任何想法如何解决?我尝试添加isMissing/IsError或将Nothing与Nothing作比较,但没有成功.

Any idea how to solve that? I tried adding isMissing / IsError or to compare to Nothing as a safeguard without success.

推荐答案

在@GSerg回答之后,我对脚本进行了如下修改,并且可以正常工作:

Following @GSerg answer, I modified the script as follows and it works:

Sub AcceptDeletions()
    Dim oChange As Revision
    For i = ActiveDocument.Revisions.Count To 1 Step -1
        If ActiveDocument.Revisions(i).Type = wdRevisionDelete Then
            ActiveDocument.Revisions(i).Accept
        End If
    Next i
End Sub

这篇关于请求的对象不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆