如何通过VBA让excel单元格的原始默认状态为“非锁定状态”。
excel \u4e2d \u5982\u4f55\u628a\u5355\u5143\u683c\u4e2d\u7684\u90e8\u5206\u5185\u5bb9\u8bbe\u7f6e \u683c\u5f0f\uff0c \u901a\u8fc7 \u6761\u4ef6\u683c\u5f0f \u6216\u8005 VBAVBA\u4e0d\u4f1a\uff0c\u521a\u8bd5\u9a8c\u51fa\u4e00\u79cd\u7528\u201c\u6761\u4ef6\u683c\u5f0f\u201d\u7684\u65b9\u6cd5\uff0c\u64cd\u4f5c\u8d77\u6765\u66f4\u52a0\u50bb\u74dc\u5f0f\uff1a
A1,A2\u600e\u4e48\u4f1a\u662f\u4e24\u5217\u6570\u636e\u5462\uff1f\u6211\u4e0b\u9762\u7684\u6b65\u9aa4\uff0c\u6682\u4e14\u6309\u7167A\u548cB\u4e24\u5217\u6570\u636e\u5199\u4e86\u54c8\uff0c\u8981\u8fbe\u5230\u76ee\u7684\u662f\uff0c\u5982\u679cB1\u4e2d\u6709A1\u7684\u5185\u5bb9\uff0c\u5c31\u628aB1\u52a0\u7c97\u3002B2\u7b49\u7b49\u4ee5\u6b64\u7c7b\u63a8\uff1a
\u5168\u9009B\u5217--\u201c\u5f00\u59cb\u201d\u9009\u9879\u5361--\u201c\u6761\u4ef6\u683c\u5f0f\u201d--\u201c\u65b0\u5efa\u89c4\u5219\u201d--\u201c\u4f7f\u7528\u516c\u5f0f\u786e\u5b9a\u8981\u8bbe\u7f6e\u683c\u5f0f\u7684\u5355\u5143\u683c\u201d\uff0c
\u5728\u201c\u4e3a\u7b26\u5408\u6b64\u516c\u5f0f\u7684\u503c\u8bbe\u5b9a\u683c\u5f0f\u201d\u90a3\u4e2a\u6587\u672c\u6846\u91cc\uff0c\u586b\u5199\uff1a
=not(iserror(findb(A1,B1)))
\u6309\u4e0b\u201c\u683c\u5f0f\u201d\u6309\u94ae\uff0c\u9009\u62e9\u201c\u52a0\u7c97\u201d
\u786e\u5b9a\uff0c\u5c31ok\u4e86\u3002
\u4f60\u8bd5\u8bd5\u5427\uff0c\u5982\u679c\u79fb\u690d\u4e0d\u5230\u4f60\u7684excel\u91cc\uff0chi\u6211\u5e2e\u4f60\u505a
\u9009\u4e2dB\u5217\uff0c\u683c\u5f0f-\u6761\u4ef6\u683c\u5f0f\uff0c\u8bbe\u7f6e\u6761\u4ef6\u4e3a\u5927\u4e8eA1\uff08\u6ce8\u610f\u9ed8\u8ba4$A$1\u6539\u4e3aA1\uff09,\u683c\u5f0f\u4e3a\u7ea2\u8272
Excel弹出“您试图更改的单元格或图表受保护,因而是只读的。若要修改受保护单元格或图表,请先使用‘撤消工作表保护’命令(在‘审阅’选项卡的‘更改’组中)来取消保护。可能会提示您输入密码。”出现这种情况,应该怎么解决呢?经过研究,找到了一种破解Excel工作表保护码的方法。第一步:打开该文件,先解除默认的“宏禁用”状态,方法是点击工具栏下的“选项”状态按钮,打开“MicrosoftOffice安全选项”窗口,选择其中的“启用此内容”,“确定”退出(图2);
再切换到“视图”选项卡,点击“宏”→“录制宏”,出现“录制新宏”窗口,在“宏名”定义一个名称为:PasswordBreaker(图3),点击“确定”退出;
第二步:再点击“宏”→“查看宏”,选择“宏名”下的“PasswordBreaker”并点击“编辑”,打开“MicrosoftVisualBasic”编辑器,用如下内容替换右侧窗口中的所有代码:
Sub PasswordBreaker()
Dim i As Integer, j As Integer, k As Integer
Dim l As Integer, m As Integer, n As Integer
Dim i1 As Integer, i2 As Integer, i3 As Integer
Dim i4 As Integer, i5 As Integer, i6 As Integer
On Error Resume Next
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
ActiveSheet.Unprotect Chr(i) & Chr(j)& Chr(k) & _
Chr(l) & Chr(m) & Chr(i1)& Chr(i2) & Chr(i3)& _
Chr(i4) & Chr(i5) & Chr(i6)& Chr(n)
If ActiveSheet.ProtectContents = False Then
MsgBox "One usable password is " & Chr(i)& Chr(j) & _
Chr(k) & Chr(l) & Chr(m)& Chr(i1) & Chr(i2)& _
Chr(i3) & Chr(i4) & Chr(i5)& Chr(i6) & Chr(n)
ActiveWorkbook.Sheets(1).Select
Range("a1").FormulaR1C1 = Chr(i) & Chr(j)& _
Chr(k) & Chr(l) & Chr(m)& Chr(i1) & Chr(i2)& _
Chr(i3) & Chr(i4) & Chr(i5)& Chr(i6) & Chr(n)
Exit Sub
End If
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
End Sub
第三步:再点击“宏”→“查看宏”,选择“宏名”下的“PasswordBreaker”并点击“执行”,密码就现形了(图4)。
第四步:切换“审阅”选项卡,点击“撤消工作表保护”,然后输入密码即可解除锁定。
你一步一步认真操作,会成功的。最后记一下密码,然后就可以使用了。
笨,既然发现了这个问题,为什么一定要清空?
将 range("a1").clear 换成 range("a1")=""
即清除换赋空不就行了嘛?
先取消保护,执行后再保护就行了
绛旓細Sub Macro1()Range("1:65536").Locked = False '瑙i櫎鍏ㄩ儴閿佸畾 Range("A1").Select '璁剧疆鏂伴攣瀹 Selection.Locked = True '寮鍚攣瀹 ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True End Sub
绛旓細鎸堿LT+F11锛屽弻鍑诲乏杈圭殑Sheet1锛岃緭鍏ュ涓嬪唴瀹广傜劧鍚庡埌琛ㄤ腑娴嬭瘯鍗冲彲銆侾rivate Sub Worksheet_Change(ByVal Target As Range)If Range("G6") = "" Then Range("G6").Interior.Color = xlNone ElseIf Range("G6") >= 90 And Range("G6") <= 100 Then Range("G6").Interior.Color = vb...
绛旓細骞跺湪K4鍗曞厓鏍艰緭鍏ワ細=SUM(D4:J4)锛岀劧鍚庡線涓嬫嫋鎷夊~鍏呭叕寮忋3銆佺偣鍑EXCEL宸ヤ綔钖勭殑宸ュ叿鈥斺斿畯 4銆佸湪寮瑰嚭鐨勭晫闈㈤夋嫨淇濇姢鍏紡锛岀偣鍑绘墽琛屻5銆佹渶鍚庢寜Alt+F11鍦ㄥ脊鍑虹殑鐣岄潰杈撳叆瀵嗙爜鍗冲彲銆傛敞鎰忎簨椤癸細涓轰簡閬垮厤鍒汉杩涘叆VBA缂栬緫妯″紡鏌ョ湅瑙i攣瀵嗙爜鎴栬呬贡淇敼浠g爜锛屾渶鍚庝竴瀹氳璁板緱灏瀹璁剧疆瀵嗙爜銆
绛旓細濡傚浘锛氳鍥句腑sheet1涓璄鍒楁诲垎瀵瑰簲鍒皊heet3涓瑽鍒楁诲垎銆1銆佸湪sheet3 B2鍗曞厓鏍艰緭鍏モ滐紳sheet1!e2鈥2銆佸洖杞﹀悗灏辫兘鏄剧ずsheet1涓璭2鍗曞厓鏍煎唴瀹广3銆鎶b2涓嬫嫋灏卞緱鍒版暣鍒楃殑鎬诲垎浜嗐
绛旓細閫氳繃VBA灏涓涓EXCEL鍗曞厓鏍肩殑鍐呭璇诲彇鍒板彟涓涓崟鍏冩牸鐨勬搷浣滄楠ゅ涓嬶細1锛屽湪vba涓垱寤轰竴涓綍鍒剁晫闈紝璁剧疆杈撳叆鎸夐挳锛岃缃緭鍏ユ寜閽唬鐮佸疄鐜拌緭鍏ュ姛鑳斤紝鍙屽嚮杈撳叆鎸夐挳锛岃緭鍏ヤ唬鐮佽繘鍏ヤ唬鐮佺獥鍙c2锛屽皢闇瑕佸湪琛ㄥ崟涓緭鍏ョ殑鏂囨湰妗嗚繛鎺ュ埌鎸囧畾鐨勫崟鍏冩牸锛岀户缁緭鍏ヤ唬鐮佷腑鏄剧ず鐨勪唬鐮侊紝骞朵娇鐢ㄦ枃鏈枃鏈鐨勫奸摼鎺ュ埌鎴戜滑瑕佽緭鍏ョ殑...
绛旓細1銆佸湪SHEET琛ㄥ唴璁剧疆濂芥寜閽紝骞舵寚瀹氬埌瀹忋2銆佸湪VBA缂栬緫鍣ㄥ唴杈撳叆濡備笅鐨勪唬鐮併傦紙姝や唬鐮佺殑鍚箟涓洪亶甯冨尯鍩熷唴鐨鍗曞厓鏍硷紝濡傛灉涓虹┖鏍硷紝鍒欓殣钘忕┖鏍兼墍鍦ㄧ殑鏁村垪銆3銆佸湪杩愯杩囩▼涓嚭鐜颁簡闂锛屼笅鏍囪秺鐣岋紝鏃犳硶杩愯銆4銆佸湪浠g爜涓殑鈥淪HEET1鈥濆伐浣滆〃鏍规湰娌℃湁锛屽洜涓篠HEET琛ㄧ殑鏍囩鍚嶇О涓衡滃浘琛ㄢ濓紝鍥犳浠g爜杩愯鏃舵壘涓嶅埌...
绛旓細姣斿缁橝1璧嬪10 [A1]=10 鍛靛懙銆備綘闂VBA锛屼互涓轰綘鑷冲皯鐭ラ亾VBA鐨勫熀鏈鍒欍傚伐鍏凤紞瀹忥紞瀹忥紙鎴朅lt+F8锛夛紝瀹忓悕杈撳叆鈥滃~绌衡濓紙杈撳叆鍏朵粬鍚嶇О涔熻锛夛紝鍗曞嚮鈥滃垱寤衡濓紝姝ゆ椂鍦╒BA缂栬緫鍣ㄩ噷鑷姩浜х敓浜嗐係ub 濉┖()End Sub 灏哰A1] = 10鏀惧叆鍏朵腑锛屾渶鍚庢槸 Sub 濉┖()[A1] = 10 End Sub 鍏抽棴VBA缂栬緫鍣紝鍐嶆...
绛旓細鎿嶄綔鏂规硶 01 鎵撳紑Excel 07锛岄変腑宸ヤ綔琛紝 鍙抽敭锛岄夋嫨鈥滄煡鐪嬩唬鐮佲濄02 VBA缂栬緫鍣ㄣ03 閫夋嫨鈥渨orksheet鈥濓紝瀵瑰綋鍓嶅伐浣滆〃杩涜鎿嶄綔銆04 鍦ㄢ滃0鏄庘濆閫夋嫨鍔ㄤ綔锛屽姩浣滃惈涔閫氳繃瀛楅潰鎰忔濆嵆鍙悊瑙o紝渚嬪 Change鍔ㄤ綔锛岃〃绀哄綋鍦ㄥ伐浣滆〃涓慨鏀鍗曞厓鏍煎唴瀹癸紝渚夸細鎵ц鐩稿簲鐨勭▼搴忋傚悓鐞嗭細BeforeDoubleClick琛ㄧず鍙屽嚮榧犳爣鍓嶆墽琛...
绛旓細绛旓細鐓т笅鍥炬墦寮浠g爜绐楀彛 鐒跺悗鎶涓嬮潰浠g爜澶嶅埗杩涘幓鍗冲彲锛歅rivate Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.HasFormula Then Exit Sub If VBA.IsNumeric(Target.Value) Then Target = Target + 1 End IfEnd Sub ...
绛旓細寰幆鍒ゆ柇绗2琛岋紝鎶鏄1鐨勬暟瀛楃殑涓嬩竴琛鍗曞厓鏍间慨鏀逛负A1鍊硷紝瀹忎唬鐮佸涓嬶細Sub 瀹1() Dim arr,j arr=activesheet.usedrange for j=1 to ubound(arr,2) if arr(2,j)=1 then arr(3,j)=arr(1,1) next j activesheet.usedrange=arrEnd Sub ...