gpt4 book ai didi

vba - 命令按钮单击与从 VBA 编辑器执行,

转载 作者:行者123 更新时间:2023-12-04 21:01:45 25 4
gpt4 key购买 nike

如果你看过这两张捕获的图像......

enter image description here

基本上,进入下一行不应更改所选选项卡,如此处所示。如果我从 VBA 编辑器中单击 F5 来执行子程序,就会发生这种情况

但是当我实际使用链接的命令按钮运行它时,它假设正在做完全相同的事情(照片显示在线程下方)。但发生的事情是这样的,

enter image description here

进入下一行实际上会以某种方式更改选项卡!

在第一个断点行中有注释告诉 excel 选择另一个选项卡......为什么要这样做。

如果我使用 F8 运行它,实际上这个问题就会消失。

更新=================================================== =============

我在 Excel VBA 中遇到了一些奇怪的行为,无法解释为什么这样做。

Sub run_simulation()   
ActiveWorkbook.Worksheets("Run Simulation").Select
ActiveSheet.CommandButton1.value = True
End Sub

该子例程选择一个工作表,然后模拟单击按钮“CommandButton1”。

当我从 VBA 编辑器中的播放图标执行此操作时,它运行良好,但是当我从另一张表上的链接按钮运行此“run_simulation”子例程时......就像这样

enter image description here

返回一个错误,指出所选工作表“run_simulation”受到保护,需要在继续之前取消保护......问题是当单击 commandButton1 时它会自动取消保护工作表。

最佳答案

Worksheet.Protect method有一个很少用的仅用户界面 范围。

来自 MSDN:

UserInterfaceOnly (optional) - True to protect the user interface, but not macros. If this argument is omitted, protection applies both to macros and to the user interface.



将此设置为 设置工作表保护时,您将能够以编程方式操作工作表对象。

关于vba - 命令按钮单击与从 VBA 编辑器执行,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34828724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com