在 2 个子例程之间传递值时出错
Error passing a value between 2 subroutine
我试图在 VBA 中的 2 个子之间传递 String,但每次我都遇到编译错误
这是我的代码
Option Explicit
Private Sub ComboBox1_DropButtonClick()
Dim value As String
value = ComboBox1.value
ComboBox1_Change value
End Sub
Private Sub ComboBox1_Change(ByVal value As String)
Dim value2 As String
value2 = value
End Sub
我收到以下错误
The routine declaration does not match the description of the event or routine of the same name
我已经尝试删除 ByVal 但仍然没有...一些提示?
The routine declaration does not match the description of the event or routine of the same name
您收到错误消息是因为 ComboBox1_Change
不支持传递参数。 ComboBox1_Change(ByVal value As String)
应该是 ComboBox1_Change()
@SiddharthRout Because I would like to get the value of the dropButton before it get changed. So when User Click on it, I get the value of the dropButton then when user change it I get the new value – ChangeWorld 10 mins ago
您不需要添加全局变量。在用户窗体中声明一个具有范围的变量。像这样
Option Explicit
Dim oldValue As String
Dim newValue As String
Private Sub ComboBox1_DropButtonClick()
oldValue = ComboBox1.value
End Sub
Private Sub ComboBox1_Change()
newValue = ComboBox1.value
MsgBox oldValue
MsgBox ComboBox1.value
End Sub
我试图在 VBA 中的 2 个子之间传递 String,但每次我都遇到编译错误
这是我的代码
Option Explicit
Private Sub ComboBox1_DropButtonClick()
Dim value As String
value = ComboBox1.value
ComboBox1_Change value
End Sub
Private Sub ComboBox1_Change(ByVal value As String)
Dim value2 As String
value2 = value
End Sub
我收到以下错误
The routine declaration does not match the description of the event or routine of the same name
我已经尝试删除 ByVal 但仍然没有...一些提示?
The routine declaration does not match the description of the event or routine of the same name
您收到错误消息是因为 ComboBox1_Change
不支持传递参数。 ComboBox1_Change(ByVal value As String)
应该是 ComboBox1_Change()
@SiddharthRout Because I would like to get the value of the dropButton before it get changed. So when User Click on it, I get the value of the dropButton then when user change it I get the new value – ChangeWorld 10 mins ago
您不需要添加全局变量。在用户窗体中声明一个具有范围的变量。像这样
Option Explicit
Dim oldValue As String
Dim newValue As String
Private Sub ComboBox1_DropButtonClick()
oldValue = ComboBox1.value
End Sub
Private Sub ComboBox1_Change()
newValue = ComboBox1.value
MsgBox oldValue
MsgBox ComboBox1.value
End Sub