我是VBA的初学者,但我尝试为学校编写一个简单的代码,但此方法不起作用,出现错误424:需要对象,我不知道为什么。
如果有专家可以帮助我!
Private Sub CommandButton1_Click()
Dim roh As Double, R As Double, w As Double, h As Double, force As Double, puissance As Double, q As Double, roh_hydro As Double
Dim pourcent As Double
roh = Cells(4, 1)
R = Cells(6, 1)
w = Cells(10, 1)
h = Cells(12, 1)
q = Cells(14, 1)
roh_hydro = Cells(16, 1)
For i = 1 To 2
force = (2 * roh * Me.Controls("ComboBoxV" & i).Value * 3.14 * R * R * w * h) / 1000000
puissance = Me.Controls("ComboBoxV" & i).Value * force
Select Case Me.Controls("ComboBoxO" & i).Value
Case Is = 30
pourcent = 10
Me.Controls("TextBoxP" & i).Value = 4 * ((pourcent / 100) * puissance) * 1000 * 0.9
Case Is = 45
pourcent = 35
Me.Controls("TextBoxP" & i).Value = 4 * ((pourcent / 100) * puissance) * 1000 * 0.9
Case Is = 60
pourcent = 59
Me.Controls("TextBoxP" & i).Value = 4 * ((pourcent / 100) * puissance) * 1000 * 0.9
End Select
Me.Controls("TextBoxPh" & i).Value = 7500 - Me.Controls("TextBoxP" & i).Value
Me.Controls("TextBox_energie" & i).Value = Me.Controls("TextBoxPh" & i).Value * Cells(5 + i, 16)
Me.Controls("TextBox_volumeC" & i).Value = Me.Controls("TextBox_energie" & i).Value / (q * roh_hydro * 1000)
Me.Controls("TextBox_volumeR" & i).Value = 102.4 - Me.Controls("TextBox_volumeC" & i).Value
Next
End Sub
祝您有美好的一天,对不起我的英语!
Private Sub UserForm_Initialize()
For i = 4 To 20 ' => pour lister les vitesses
ComboBox_Vitesse.AddItem Cells(i, 2) 'Ajoute les valeurs des cellules B4 à B20 avec la boucle
Next
For i = 4 To 22 ' => pour lister les orientations
ComboBox_orientation.AddItem Cells(i, 8)
Next
End Sub
代码的结尾,我只得到了这个,当我尝试启动时,我得到了错误424,当我想看看错误在哪里时,用此代码打开一个新窗口
Sub Bouton2_Cliquer()
UserForm1.Show
End Sub
,第二行突出显示。