Page 1 of 1

ต้องการให้กล่อง CommandButton หายไปเมื่อสั่งให้ทำงาน

Posted: Wed May 22, 2013 10:26 am
by yodpao.b
ต้องการให้กล่อง CommandButton หายไปเมื่อสั่งให้ทำงาน

เรียนอาจาร์ยครับ
จุดประสงค์คือ - เมื่อมองในเซล K2 = False ให้ CommandButton 2 หายไป
- เมื่อมองในเซล K2 = True ให้ CommandButton 1 หายไป

ข้อแม้คือต้องเปิด UserForm8Document2 แล้วคลิกช่อง แสดงใบยืม

โคดที่ผิด

Code: Select all

Private Sub CommandButton1_Click()

Unload Me

Sheets("Document1").Select
    
If Range("K2") <> True Then
CommandButton1.Visible = True
CommandButton2.Visible = False
End If

If Range("K2") = True Then
CommandButton1.Visible = False
CommandButton2.Visible = True
End If

    
    
End Sub
จากที่ error ดูหมือนมันจะไม่รู้จักคำสั่งด้านล่างครับ
CommandButton1.Visible = False
CommandButton2.Visible = True

เรียนอาจาร์ยช่วยแนะนำหน่อยครับ

Re: ต้องการให้กล่อง CommandButton หายไปเมื่อสั่งให้ทำงาน

Posted: Wed May 22, 2013 11:35 am
by tupthai
จากที่ error ดูหมือนมันจะไม่รู้จักคำสั่งด้านล่างครับ
CommandButton1.Visible = False
CommandButton2.Visible = True
Errorเนื่องจากไม่มี CommandButton2 ใน userform
ให้เพิ่มCommandButton2เข้าไป และลบ Code Unload Me
ใน Private Sub CommandButton1_Click()

Re: ต้องการให้กล่อง CommandButton หายไปเมื่อสั่งให้ทำงาน

Posted: Wed May 22, 2013 1:04 pm
by yodpao.b
เรียนคุณ tupthai
"ให้เพิ่มCommandButton2เข้าไป และลบ Code Unload Me"
ไม่เข้าใจครับ
เนื่่องจาก CommandButton1 และ CommandButton2 อยู่ใน ซีต ไม่ใช่อยู่ในฟอร์ม
ความต้องการคือ ให้ คือ ให้ CommandButton ใน ซีต หายไป
ไม่ใช่ในฟอร์ม

Re: ต้องการให้กล่อง CommandButton หายไปเมื่อสั่งให้ทำงาน

Posted: Wed May 22, 2013 3:01 pm
by snasui
:D ลองปรับ Code เป็นตามด้านล่างครับ

Code: Select all

'Other code
ActiveSheet.CommandButton1.Visible = True
ActiveSheet.CommandButton2.Visible = False
'Other code

Re: ต้องการให้กล่อง CommandButton หายไปเมื่อสั่งให้ทำงาน

Posted: Wed May 22, 2013 3:24 pm
by yodpao.b
ขอบคุณครับ