HỎI CODE TỰ ĐỘNG Unprotect shared workbook và Protect shared workbook

Liên hệ QC

khoahoc78

Thành viên chính thức
Tham gia
27/9/10
Bài viết
55
Được thích
1
Xin giúp đỡ code khi mở file và 1 form xuất hiện khi đó ấn 1 nút lệnh thì Unprotect shared workbook
Khi đóng file thì tự động Protect shared workbook
Xin anh em giúp đỡ
 
Xin giúp đỡ code khi mở file và 1 form xuất hiện khi đó ấn 1 nút lệnh thì Unprotect shared workbook
Khi đóng file thì tự động Protect shared workbook
Xin anh em giúp đỡ
Bạn sử dụng 2 sub như sau:
PHP:
Private Sub CommandButton1_Click()
    ThisWorkbook.UnprotectSharing SharingPassword:="GPE"
End Sub
PHP:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    ThisWorkbook.ProtectSharing SharingPassword:="GPE"
End Sub
 
Upvote 0
Cảm ơn bạn nhiều nhưng mình làm thử thì có lỗi báo như sau : Method'UnpropectSharring'of object'_workbook' failed
Lỗi 1004

Nếu là nút lệnh ở sheets thì cũng code như trên à. Mình thữ lại được trong form. nhưng ở ngoài sheet thì chịu.
Cảm ơn bạn nhiều.
 
Lần chỉnh sửa cuối:
Upvote 0
Bạn thử thay "GPE" thành Password thực sự của bạn xem sao.

Sau một hồi thử thì hình như vầy mới đúng:
PHP:
Sub CommandButton1_Click()
    ThisWorkbook.UnprotectSharing ("GPE")
End Sub
Trên Form hay trong Sheet thì cũng như nhau thôi, bởi vì đều tác động tới cùng một đối tượng là ThisWorkbook.
 
Lần chỉnh sửa cuối:
Upvote 0
Cảm ơn bạn, mình thữ lại đúng là như vậy.
Cho mình hỏi thêm, khi trong workbook mình unpropect, rồi sau đó propect bằng code thì ở cửa sổ của code lại lộ ra mất, làm thế nào để cửa sổ của code không hiện ra, để người khác không thấy được. Nếu Unpropect share workbook, sau đó propect share workbook thì cửa sổ code cũng sẽ bị lộ ra, nếu người khác xâm nhập.
Một lần nữa cảm ơn bạn. Giúp mình nhé.
Va một vấn đề nữa. Mình muốn tạo 1 combobox có danh sách là số trang của sheet, nếu chọn đúng số trang thì chỉ unhide các dòng của trang đó, còn các dòng khác thì hide đi.
 
Upvote 0
Cảm ơn bạn, mình thữ lại đúng là như vậy.
Cho mình hỏi thêm, khi trong workbook mình unpropect, rồi sau đó propect bằng code thì ở cửa sổ của code lại lộ ra mất, làm thế nào để cửa sổ của code không hiện ra, để người khác không thấy được. Nếu Unpropect share workbook, sau đó propect share workbook thì cửa sổ code cũng sẽ bị lộ ra, nếu người khác xâm nhập.
Một lần nữa cảm ơn bạn. Giúp mình nhé.
Va một vấn đề nữa. Mình muốn tạo 1 combobox có danh sách là số trang của sheet, nếu chọn đúng số trang thì chỉ unhide các dòng của trang đó, còn các dòng khác thì hide đi.
- Yêu cầu 1: Bạn có thể xử lý bằng cách khóa VBAProject lại như trên hình sau:
Khoa VBAProject.JPG
- Yêu cầu 2: Mình chưa làm được. Xin nhờ các anh chị em khác ra tay.
 
Lần chỉnh sửa cuối:
Upvote 0
Vậy cho mình hỏi. Nếu lỡ quên pass cua unproject workbook thì dùng mã nào để mở? Mình biết có mã để mở unproject sheet.
 
Upvote 0
Mình đã thử rất nhiều cách và kết quả đều là Fail.
Sau khi check kỹ thì khôngđược phép Unprotect khi share file:

In a shared workbook, you cannot:However, this functionality is available:Create an Excel tableInsert or delete blocks of cellsYou can insert entire rows and columns.Delete worksheetsMerge cells or split merged cellsSort or filter by formattingYou can sort or filter by number, text, or date, apply built-in filters, and filter by using the Search box.Add or change conditional formatsYou can use existing conditional formats as cell values change.Add or change data validationYou can use data validation when you type new values.Create or change charts or PivotChart reportsYou can view existing charts and reports.Insert or change pictures or other objectsYou can view existing pictures and objects.Insert or change hyperlinksYou can use existing hyperlinks.Use drawing toolsYou can view existing drawings and graphics.Assign, change, or remove passwordsYou can use existing passwords.Protect or unprotect worksheets or the workbookYou can use existing protection.Create, change, or view scenariosUse the Text to Columns commandGroup or outline dataYou can use existing outlines.Insert automatic subtotalsYou can view existing subtotals.Create data tablesYou can view existing data tables.Create or change PivotTable reportsYou can view existing reports.Create or apply slicersExisting slicers in a workbook are visible after the workbook is shared, but they cannot be changed for standalone slicers or be reapplied to PivotTable data or Cube functions. Any filtering that was applied for the slicer remains intact, whether the slicer is standalone or is used by PivotTable data or Cube functions in the shared workbook.Create or modify sparklinesExisting sparklines in a workbook are displayed after the workbook is shared and will change to reflect updated data. However, you cannot create new sparklines, change their data source, or modify their properties.Write, record, change, view, or assign macrosYou can run existing macros that don't access unavailable features. You can also record shared workbook operations into a macro stored in another nonshared workbook.Add or change Microsoft Excel 4 dialog sheetsChange or delete array formulasExcel will calculate existing array formulas correctly.Work with XML data, including:Import, refresh, and export XML dataAdd, rename, or delete XML mapsMap cells to XML elementsUse the XML Source task pane, XML toolbar, or XML commands on the Data menuUse a data form to add new dataYou can use a data form to find a record.
 
Upvote 0
Web KT

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

Back
Top Bottom