VBA检查是否已单击按钮 [英] VBA Check if button has been clicked

查看:248
本文介绍了VBA检查是否已单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这是一个简单的解决方法,但是我已经在这个麻烦点停留了几个小时。

I think this is an easy fix, but I've been stuck at this trouble spot for hours now.

基本上在excel工作表中,我分配了两个按钮到宏:1和2。如果用户先单击1,然后单击2,则2会消耗掉1中的某些变量。但是如果首先单击2,则我需要2才能独立操作。因此,我需要在2代码中以某种方式询问是否单击了1个按钮。

Basically in the excel worksheet I have two buttons assigned to macros: 1 and 2. If the user clicks 1 first and then clicks then 2, 2 runs off of some of the variables from 1. But I need 2 to be able to operate independently if 2 is clicked first. Therefore, I need some way in the 2 code to ask if 1 button has been clicked.

1和2都是公共子。我认为定义中缺少某些内容,但不确定。

Both 1 and 2 are public subs. I think there is something that I am missing with the definitions, but I'm not sure.

简单示例:

Public Sub 1()
do this
End Sub

Public Sub 2()
If 1 clicked then
   process a
Else
   process b
End if
End Sub


推荐答案

设置公共布尔值并使用

例如

Dim ButtonOneClick As Boolean 'Make sure this is before all subs

Sub Button1_Click()
ButtonOneClick = True
End Sub

Sub Button2_Click()
If ButtonOneClick Then
    MsgBox "Button 1 Was Clicked"
Else
    MsgBox "Button 1 Was NOT Clicked"
End If

ButtonOneClick = False
End Sub

这篇关于VBA检查是否已单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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