Word VBA删除按钮不起作用 [英] Word vba delete button not working

查看:94
本文介绍了Word VBA删除按钮不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行后出现错误'91':对象变量或未设置块变量"

I got "error '91': Object variable or With block variable not set" after running:

For Each obj In ActiveDocument.InlineShapes
    If obj.OLEFormat.Object.Name = "Button" Then '<-error line
        obj.Delete
    End If
Next

我认为我需要将obj声明为InlineShape或Object,但是结果是相同的.我确定我有名为Button的命令按钮,并且知道名称和标题之间的区别,但两者都不起作用.该代码是在按下同一按钮后运行的代码的一部分.

I thought that I need to declare obj as InlineShape or as Object, but results were the same. I am sure that I have command button with name Button and I know diference between name and caption, neither works. This code is part of the code that runs after the same button is pressed.

推荐答案

我已经测试了以下有效的代码:

I've tested the below code which works:

Sub delete()

Dim obj As Object

For Each obj In ActiveDocument.InlineShapes
    If obj.OLEFormat.Object.Name = "Button" Then
        obj.delete
    End If
Next obj

End Sub

这篇关于Word VBA删除按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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