VBA对象不支持此属性或方法 [英] VBA Object doesn't support this property or method

查看:2583
本文介绍了VBA对象不支持此属性或方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要简单地计算一张单据的数量。我的代码是:

I need to simply count the number of areas on a sheet. The code I have is :

Sub areas()
   Dim i As Long
   i = Worksheets("Sheet2").Selection.Areas.Count
   MsgBox i
End Sub

但是由于某些原因,我收到错误消息对象不支持此属性或方法。我不知道为什么。这个代码基本上只是从微软网站复制出来的。

But for some reason I get the error message "Object doesn't support this property or method." I have no idea why. This code was basically just copied from the Microsoft website.

我甚至不能立即打印窗口打印 Worksheets(Sheet2)。Selection.Areas.Count 部分。

I can't even get the immediate window to print the Worksheets("Sheet2").Selection.Areas.Count portion.

任何快速帮助?我正在使用Excel 2010。

Any quick help? I am using Excel 2010.

谢谢。

推荐答案


对象不支持此属性或方法。

Object doesn't support this property or method.

一个东西。这就像一条链。

Think of it like if anything after the dot is called on an object. It's like a chain.

一个对象是一个类实例。类实例支持在类类型定义中定义的一些属性。它暴露了VBE告诉你的任何Intelli-sense(有一些隐藏的成员,但它与这个无关)。所以在每个点之后,您将获得Intelli-sense(该白色下拉菜单),试图帮助您选择正确的动作

An object is a class instance. A class instance supports some properties defined in that class type definition. It exposes whatever intelli-sense in VBE tells you (there are some hidden members but it's not related to this). So after each dot . you get intelli-sense (that white dropdown) trying to help you pick the correct action.

你可以从前面到后面或者回到前面开始,一旦你明白这个工作原理,你将能够确定问题出现的位置)

(you can start either way - front to back or back to front, once you understand how this works you'll be able to identify where the problem occurs)

在代码区域的任何地方输入此字段

Type this much anywhere in your code area

Dim a As Worksheets
a.

您从VBE获得帮助,这是一个名为Intelli-sense

you get help from VBE, it's a little dropdown called Intelli-sense

它列出了特定对象暴露给任何用户的所有可用操作。您不能看到 Worksheets()类的 .Selection 成员。这是错误告诉你的。

It lists all available actions that particular object exposes to any user. You can't see the .Selection member of the Worksheets() class. That's what the error tells you exactly.


对象不支持此属性或方法。

Object doesn't support this property or method.

如果您查看 MSDN上的示例

Worksheets("GRA").Activate
iAreaCount = Selection.Areas.Count

激活该工作表首先调用选择... 它不连接在一起,因为选择不是的工作表()类。简单来说,您不能前缀 选择

It activates the sheet first then calls the Selection... it's not connected together because Selection is not a member of Worksheets() class. Simply, you can't prefix the Selection

Sub DisplayColumnCount()
    Dim iAreaCount As Integer
    Dim i As Integer

    Worksheets("GRA").Activate
    iAreaCount = Selection.Areas.Count

    If iAreaCount <= 1 Then
        MsgBox "The selection contains " & Selection.Columns.Count & " columns."
    Else
        For i = 1 To iAreaCount
        MsgBox "Area " & i & " of the selection contains " & _
        Selection.Areas(i).Columns.Count & " columns."
        Next i
    End If
End Sub

from HERE

这篇关于VBA对象不支持此属性或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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