当前位置:编程学习 > VB >>

谁能看看这个代码问题在哪?

Private Sub CommandButton1_Click()
If TextBox1.Text = "" Or TextBox2.Text = "" Then '登陆按钮
MsgBox "请输入帐号(或密码)"
ElseIf TextBox1.Text = "admin" And TextBox2.Text = "888" Then Sheets("首页").Select
ElseIf TextBox1.Text = "abc" And TextBox2.Text = "123" Then Sheets("成员首页").Select
Else
MsgBox "输入错误"
End If
End Sub




为什么我点击后没反映呢?
--------------------编程问答-------------------- F8单步执行下,看问题出在哪行代码 --------------------编程问答-------------------- Private Sub CommandButton1_Click()
If TextBox1.Text = "" Or TextBox2.Text = "" Then '登陆按钮
MsgBox "请输入帐号(或密码)"
ElseIf TextBox1.Text = "admin" And TextBox2.Text = "888" Then Sheets("首页").Activate
ElseIf TextBox1.Text = "abc" And TextBox2.Text = "123" Then Sheets("成员首页").Activate
Else
MsgBox "输入错误"
End If
End Sub
--------------------编程问答-------------------- 你 Sheets("首页").Select 有什么目的,或者说你要达到什么目的? --------------------编程问答-------------------- 不要用这么多ELSEIF
直接用多个IF语句反而更清楚 --------------------编程问答-------------------- 问题出在Sheets  --------------------编程问答-------------------- 有反应了,你没觉察到~~~ --------------------编程问答-------------------- 应该是楼上的答案了 --------------------编程问答-------------------- 怎么没加sheets.Visible = False --------------------编程问答-------------------- 是不是在窗体控件里面写的代码,试一下吧sheet改为 thisworkbook.worksheets --------------------编程问答-------------------- 焦点问题
sheet是引用excel里的表单
补充:VB ,  VBA
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,