มิตรภาพ
26 Jun 2007, 13:08
ผมมีไฟล์สำหรับทำหน้าที่เป็นฟอร์มสำหรับกรอกข้อมูล จากนั้นจึงค่อยนำข้อมูลไปเก็บในฐานข้อมูลด้วย VBA ดังนั้น ผมจึงไม่ต้องการให้ User คนใดบันทึกไฟล์ที่เป็นแบบฟอร์มได้ ควรมีแต่ผมคนเดียวเท่านั้นที่สามารถแก้ไขและบันทึกไฟล์นี้ได้
ผมได้โค้ดนี้จากเน็ตครับ
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Msg
If ThisWorkbook.Saved = False Then
Msg = "Saving Changes Is Disabled In Evaluation Version"
Msg = MsgBox(Msg, vbOKCancel + vbExclamation)
Cancel = True
'Interupt here when saving this code for the first time. I type "bug" to interupt.
'Debug (delete bug) and reset- then save process will continue.
'In future you can set ThisWorkbook Saved property to True to save changes.
End If
End Sub
สามารถป้องกันการบันทึกได้เป็นอย่างดีครับ
แต่ปัญหาก็คือ ผมไม่สามารถ "บันทึก" โค้ด "ห้ามบันทึก" เข้ากับไฟล์นี้ได้ เนื่องจาก 2 บรรทัดนี้
'Interupt here when saving this code for the first time. I type "bug" to interupt.
'Debug (delete bug) and reset- then save process will continue.
ผมอ่านแล้วยังไม่เข้าใจวิธีทำครับ จึงขอเรียนถาม ขอคำแนะนำในเรื่องนี้ด้วยครับ ขอบคุณครับผม
ผมได้โค้ดนี้จากเน็ตครับ
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Msg
If ThisWorkbook.Saved = False Then
Msg = "Saving Changes Is Disabled In Evaluation Version"
Msg = MsgBox(Msg, vbOKCancel + vbExclamation)
Cancel = True
'Interupt here when saving this code for the first time. I type "bug" to interupt.
'Debug (delete bug) and reset- then save process will continue.
'In future you can set ThisWorkbook Saved property to True to save changes.
End If
End Sub
สามารถป้องกันการบันทึกได้เป็นอย่างดีครับ
แต่ปัญหาก็คือ ผมไม่สามารถ "บันทึก" โค้ด "ห้ามบันทึก" เข้ากับไฟล์นี้ได้ เนื่องจาก 2 บรรทัดนี้
'Interupt here when saving this code for the first time. I type "bug" to interupt.
'Debug (delete bug) and reset- then save process will continue.
ผมอ่านแล้วยังไม่เข้าใจวิธีทำครับ จึงขอเรียนถาม ขอคำแนะนำในเรื่องนี้ด้วยครับ ขอบคุณครับผม