将 VBA 范围命令与其他工作表中的 ActiveX 按钮一起使用

Using VBA range commands with ActiveX buttons in other sheets

在构建用户界面时,我使用了 VBA2010 中的 ActiveX 按钮。我先写宏,检查它们,然后将它们复制到 ActiceX 按钮代码中。

宏然后在另一个 sheet 的范围命令处崩溃。为了测试它,我将命令分开:

Sheets("Data").Visible = xlSheetVisible 
Sheets("Data").Select                   
Columns("O:O").Select         ' The code crashes here

结果我收到 1004 运行时错误。 我发现了一个类似的话题,似乎也没有解决。

Unable to Execute Macro With ActiveX Controls (Excel VBA)

非常感谢您的帮助。 提前致谢!

Select 不是 recommended.Modify 您要

的代码
 Dim ws As Worksheet
 Set ws = Sheets("Data")
 ws.Visible = xlSheetVisible
 ws.Select
 With ws
 .Columns("O:O").Select
 End With