2017-09-06 69 views
1

我試圖複製一些代碼網上,我從以下鏈接找到... http://www.ozgrid.com/forum/showthread.php?t=15325VBA鎖定我的工作表

我嘗試使用一些代碼通過按鈕我的Excel工作簿中導入圖像,並驗證碼鎖定我的工作表,當它提示輸入密碼我試着打不佔上風進入...我用下面

Sub BrowsePicture() 
Dim Pict 
Dim ImgFileFormat As String 
Dim PictCell As Range 
Dim Ans As Integer 

ActiveSheet.Protect True, True, True, True, True 
ImgFileFormat = "Image Files (*.bmp),others, tif (*.tif),*.tif, jpg (*.jpg),*.jpg" 

GetPict: 
Pict = Application.GetOpenFilename(ImgFileFormat) 
'Note you can load in any nearly file format 
If Pict = False Then End 

Ans = MsgBox("Open : " & Pict, vbYesNo, "Insert Picture") 
If Ans = vbNo Then GoTo GetPict 

'Now paste to userselected cell 
GetCell: 
Set PictCell = Application.InputBox("Select the cell to insert into", Type:=8) 
If PictCell.Count > 1 Then MsgBox "Select ONE cell only": GoTo GetCell 
PictCell.Select 
ActiveSheet.Pictures.Insert(Pict).Select 
End Sub 

代碼請幫幫忙!我投入了大量的工作,到這個電子數據表,我不能編輯任何內容:(

+0

根據[Microsoft文檔](https://msdn.microsoft.com/en-us/vba/excel-vba/),'ActiveSheet.Protect True,True,True,True,True'行鎖定電子表格文章/工作表保護法,EXCEL)。 [文檔](https://msdn.microsoft.com/en-us/vba/excel-vba/articles/worksheet-unprotect-method-excel)也建議'ActiveSheet.Unprotect'應該解鎖它,假設沒有密碼組。 – Afforess

回答

5

ActiveSheet.Protect True, True, True, True, True第一個參數是密碼,所以你設置的密碼是True(注:不"True",實際值True,你將無法從標準撤消對話框鍵入)。

您可以從即時窗口執行命令

ActiveSheet.Unprotect True 

(再次取消保護它,或者你可以寫一個小小組去做)

+0

你是救世主!非常感謝! 我以爲這就是我所做的,我嘗試輸入它,但它必須把它作爲真正的標誌是密碼而不是實際的單詞。 我真的不能夠感謝你! – Maldred