Code: Select all
Private Sub Workbook_Open()
Application.CommandBars("Standard").Visible = False
Application.CommandBars("Formatting").Visible = False
Application.DisplayFormulaBar = False
Application.CommandBars("àÁ¹Ù¹Õéãªé¡Ñºâ»Ãá¡ÃÁ¨Ñ´¡Òðҹ¢éÍÁÙŤèÒÅèǧàÇÅÒ").Visible = True
Application.CommandBars("Worksheet Menu Bar").Enabled = False
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("Worksheet Menu Bar").Enabled = True
Application.CommandBars("Standard").Visible = True
Application.CommandBars("Formatting").Visible = True
Application.DisplayFormulaBar = True
Application.CommandBars("àÁ¹Ù¹Õéãªé¡Ñºâ»Ãá¡ÃÁ¨Ñ´¡Òðҹ¢éÍÁÙŤèÒÅèǧàÇÅÒ").Visible = False
End Sub
จาก Code ด้านบน ลองทำไฟล์ตัวอย่างดู เมื่อสั่งปิดไฟล์ โปรแกรมจะคืนค่าเดิม
หลังจากนั้นลองเปิด Excel new book จะเห็นว่าทุกอย่างขึ้นเป็นปกติเหมือนเดิม

แต่เมื่อลองนำไปใช้กับไฟล์จริงมีปัญหาตรงที่
เมื่อเปิด ปิด โปรแกรม ก็เป็นปกติ แต่พอ
เปิด Excel new book จะเห็นว่า code ด้านล่างไม่ทำงาน
Code: Select all
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("Worksheet Menu Bar").Enabled = True
Application.CommandBars("Standard").Visible = True
Application.CommandBars("Formatting").Visible = True
Application.DisplayFormulaBar = True
Application.CommandBars("àÁ¹Ù¹Õéãªé¡Ñºâ»Ãá¡ÃÁ¨Ñ´¡Òðҹ¢éÍÁÙŤèÒÅèǧàÇÅÒ").Visible = False
End Sub

มันแปลกที่ไฟลตัวอย่างทำงานได้ตรงเป้าหมาย
แต่ไฟล์จริงกับเกิดปัญหา
ทั้งนี้ได้แนบไฟล์มาให้อาจารย์ช่วยดู
You do not have the required permissions to view the files attached to this post.