Code protect/unprotect sheet (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

Cá ngừ F1

( ͡° ͜ʖ ͡°)
Thành viên BQT
Moderator
Tham gia
1/1/08
Bài viết
2,579
Được thích
3,723
Donate (Momo)
Donate
Giới tính
Nam
Nghề nghiệp
Quan hệ.. và quan hệ..
E có đoạn code sau:
Mã:
[COLOR=#333333][FONT=lucida grande]...........[/FONT][/COLOR]
[COLOR=#333333][FONT=lucida grande] If ActiveWorkbook.MultiUserEditin[/FONT][/COLOR][COLOR=#333333][FONT=lucida grande]g Then ActiveWorkbook.ExclusiveAccess[/FONT][/COLOR]
[COLOR=#333333][FONT=lucida grande]   With Sheets("data").Unprotect[/FONT][/COLOR]
[COLOR=#333333][FONT=lucida grande]     Call VlookUp[/FONT][/COLOR][COLOR=#333333][FONT=lucida grande]
     Call VlookUp2
     Call VlookUp3
   Sheets("data").Protect
  End With
  ActiveWorkbook.SaveAs FileName:=ActiveWorkbook.FullName, _
accessMode:=xlShared
.....[/FONT][/COLOR]

E đang muốn hỏi cái đoạn Protect/unprotect
Khi code chay đến đoạn unprotect có hỏi pass.. nhưng khi protect lại thì chẳng hỏi j (nghĩa là có protect nhưng ko có pass). Vậy làm thế nào để protect lại vẫn có pass như lúc đầu..
.....
E có tham khảo thì đặt pass ngay sau protect, ví dụ:
With Sheets("data").Unprotect("pass") .... Sheets("data").Protect("pass")
Tuy nhiên, có khúc mắc nho nhỏ:
- Như thế tính bảo mật hơi kém.. view code là nhìn thấy hết
- Khi protect e có tích chọn một số thứ trong hộp kiểm như: cho phép dùng filter/pivot table... Nếu sử dụng code:

Mã:
[COLOR=#333333][FONT=lucida grande]If ActiveWorkbook.MultiUserEditing Then ActiveWorkbook.ExclusiveAccess[/FONT][/COLOR][COLOR=#333333][FONT=lucida grande]
[/FONT][/COLOR][COLOR=#333333][FONT=lucida grande]With Sheets("data").Unprotect("pass")
Call VLookup
Call VlookUp2
Call VlookUp3
Sheets("data").Protect ("pass")
End With
ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.FullName, _
accessMode:=xlShared[/FONT][/COLOR][COLOR=#333333][FONT=lucida grande]
[/FONT][/COLOR]

thì sau khi code chạy xong không còn sử dụng được filter/pivot table (mà chỉ mặc định protect ở select lock cells và select unlocked cells)
E cảm ơn ạh
 
Lần chỉnh sửa cuối:
E có đoạn code sau:
Mã:
[COLOR=#333333][FONT=lucida grande]If ActiveWorkbook.MultiUserEditing Then ActiveWorkbook.ExclusiveAccess[/FONT][/COLOR][COLOR=#333333][FONT=lucida grande]
[/FONT][/COLOR][COLOR=#333333][FONT=lucida grande]Sheets("data").Unprotect("pass")
Call VLookup
Call VlookUp2
Call VlookUp3
Sheets("data").Protect ("pass")
ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.FullName, _
accessMode:=xlShared[/FONT][/COLOR][COLOR=#333333][FONT=lucida grande]
[/FONT][/COLOR]


Tự nhiên thêm cái With và End With chi cho tốn điện nước vậy? Cước 3G lúc này cao lắm nha.
Còn chuyện bảo mật code hả? Quên đi nhé. Vài giây là phá sạch.
 
Lần chỉnh sửa cuối:
Upvote 0
Bạn Record Marco thử xem: Mở Marco > Review > Protect > Gõ pass và các tùy chọn > Đóng Marco và xem code.

Dùng cái này để bảo mật không ổn 1 chút nào. Excel Password Recovery Lastic, Office Password Recovery Toolbox, Excel Password Remover, Passware Kit Professional... đã đủ chưa --=0
 
Upvote 0
Tự nhiên thêm cái With và End With chi cho tốn điện nước vậy? Cước 3G lúc này cao lắm nha.
Còn chuyện bảo mật code hả? Quên đi nhé. Vài giây là phá sạch.
Dạ.. cảm ơn anh.. e học kiểu mò.. chưa hiểu rõ bản chất của các cặp lệnh.. chưa biết tiết kiệm "Tắt khi không sử dụng" ạh
 
Upvote 0
Dạ.. cảm ơn anh.. e học kiểu mò.. chưa hiểu rõ bản chất của các cặp lệnh.. chưa biết tiết kiệm "Tắt khi không sử dụng" ạh
Theo mình được thông tin từ các anh chị đi trước thì ít nhất cũng 90 % thành viên trên GPE đều 'mò' nhiều mà 'ra' đủ thứ.
 
Upvote 0
Theo mình được thông tin từ các anh chị đi trước thì ít nhất cũng 90 % thành viên trên GPE đều 'mò' nhiều mà 'ra' đủ thứ.
E có mò mẫm để thêm vài sự lựa chọn khi protect
Application.DisplayAlerts = False
If ActiveWorkbook.MultiUserEditing Then ActiveWorkbook.ExclusiveAccess
Sheets("data").Unprotect ("aaaaa")
Call VlookUp
Call VlookUp2
Call VlookUp3
Sheets("data").Protect("aaaaa") Contents:=True, Scenarios:=True _
, AllowFiltering:=True
ActiveWorkbook.SaveAs FileName:=ActiveWorkbook.FullName, _
accessMode:=xlShared
Application.DisplayAlerts = True
thì có báo lỗi syntax error ở dòng bôi đỏ -> ko biết mò chỗ nào nữa ạh -> đọc help ko hiểu chi luôn !$@!!
 
Upvote 0
E có mò mẫm để thêm vài sự lựa chọn khi protect

thì có báo lỗi syntax error ở dòng bôi đỏ -> ko biết mò chỗ nào nữa ạh -> đọc help ko hiểu chi luôn !$@!!

Thiếu mất cái dấu phẩy thì báo lỗi là đúng rồi
Cú pháp ghi rõ ràng mà

expression.Protect(Password, DrawingObjects, Contents, Scenarios, UserInterfaceOnly)
 
Upvote 0
Thiếu mất cái dấu phẩy thì báo lỗi là đúng rồi
Cú pháp ghi rõ ràng mà

expression.Protect(Password, DrawingObjects, Contents, Scenarios, UserInterfaceOnly)
Dạ... thế mới thấy việc ghi lại các marco và cú pháp code có sự khác nhau ạh... )(&&@@
 
Upvote 0
Lại tiếp tục record macro và.. suy nghĩ tiếp
Mấy cái này chỉ là chuyện vặt
Đã record và sửa lại thành:
Mã:
Sheets("data").Protect Password:=catlinh, Contents:=True, _
Scenarios:=True, AllowFiltering:=True
--> chạy ngon lành ạh...
Còn cấu trúc:
expression.Protect(Password, DrawingObjects, Contents, Scenarios, UserInterfaceOnly, AllowFormattingCells, AllowFormattingColumns, AllowFormattingRows, AllowInsertingColumns, AllowInsertingRows, AllowInsertingHyperlinks, AllowDeletingColumns, AllowDeletingRows, AllowSorting, AllowFiltering, AllowUsingPivotTables) -> áp dụng ntn ạh?
 
Lần chỉnh sửa cuối:
Upvote 0
Đã record và sửa lại thành:
Mã:
Sheets("data").Protect Password:=catlinh, Contents:=True, _
Scenarios:=True, AllowFiltering:=True
--> chạy ngon lành ạh...
Còn cấu trúc:
expression.Protect(Password, DrawingObjects, Contents, Scenarios, UserInterfaceOnly, AllowFormattingCells, AllowFormattingColumns, AllowFormattingRows, AllowInsertingColumns, AllowInsertingRows, AllowInsertingHyperlinks, AllowDeletingColumns, AllowDeletingRows, AllowSorting, AllowFiltering, AllowUsingPivotTables) -> áp dụng ntn ạh?
Thì y chang mấy cái kia. Muốn xài cái nào thì cứ cho nó bằng True. Cứ mò riết là được hà. Mình cũng xơi VBA theo hướng này, chứ có học hành cơ bản gì đâu
 
Lần chỉnh sửa cuối:
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom