首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >动态按钮-运行时错误1004 -无法获取工作表类的按钮属性

动态按钮-运行时错误1004 -无法获取工作表类的按钮属性
EN

Stack Overflow用户
提问于 2018-07-04 09:01:59
回答 1查看 1.6K关注 0票数 0

您好,我收到了“运行时错误1004 -无法获取工作表类的按钮属性”,它来自靠近底部Set b = Worksheets("Form").Buttons(Application.Caller) 'references button的一行。

我基本上是在尝试将列中的数据复制到动态按钮旁边,该按钮出现在透视表的完全展开的字段旁边。我已经让按钮看起来很好,我只需要它们在单击特定按钮时将相邻单元格中的数据复制到另一个工作表中的列表中。

代码语言:javascript
复制
Sub buttonGenerator()

Dim btn As Button
Application.ScreenUpdating = False
ActiveSheet.Buttons.Delete
Dim t As Range
Dim size As Long

size = Worksheets("Form").PivotTables("Pivottable1").TableRange2.Rows.Count 'returns number of rows in expanding pivot table

For i = 2 To size Step 1 'cycles through from row 2 to last row of pivot table
    If Not IsEmpty(Worksheets("Form").Range(Cells(i, 4), Cells(i, 4))) Then 'only shows button if last col of pivot table has data
      Set t = Worksheets("Form").Range(Cells(i, 5), Cells(i, 5))
      Set btn = Worksheets("Form").Buttons.Add(t.Left, t.Top, t.Width, t.Height)
      With btn
        .OnAction = "btnS" 'call btnS subroutine
        .Caption = "Button" & i 'button label
        .Name = "Button" & i 'button name
        End With
    End If

Next i

Application.ScreenUpdating = False

End Sub


Public Sub btnS()

Dim b As Object
Dim r As Integer
Dim c As Integer

Set b = Worksheets("Form").Buttons(Application.Caller) 'references button
With b.TopLeftCell 'returns row and col of button pushed
r = .row
c = .col
End With

origin = Range(r, c)
dest = Worksheets("Form Output").Range(Cells(1, 1))
dest.Value = origin.Value

End Sub
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51164543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档