ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 522|回复: 0

【求助】excel中的工作表如何取消自动保护

[复制链接]

TA的精华主题

TA的得分主题

发表于 2019-12-16 10:17 | 显示全部楼层 |阅读模式
本帖最后由 whj188 于 2019-12-18 09:18 编辑

excel表格每次取消保护后,点击一下原来保护的单元格,马上又自动锁上了,求问代码应该怎么改才会不自动保护?另外如果有大神能解释一下对应语句的含义就更好了,谢谢_(:з」∠)_
Dim arr
Sub Hsaness()
Sheet75.Select
ActiveSheet.Unprotect Password:="abc@1"
Sname = ActiveSheet.Name
lastrow = Worksheets(Sname).Range("A65535").End(xlUp).Row

If lastrow > 5 Then
Range("O5:AD5").Select
Selection.AutoFill Destination:=Range("O5:AD" & lastrow), Type:=xlFillDefault
End If
Columns("AA:AA").Select
Selection.Copy
Columns("P:P").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlPasteSpecialOperationNone, SkipBlanks:=False, Transpose:=False
Columns("AB:AB").Select
Selection.Copy
Columns("Q:Q").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlPasteSpecialOperationNone, SkipBlanks:=False, Transpose:=False
Columns("AC:AC").Select
Selection.Copy
Columns("S:S").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlPasteSpecialOperationNone, SkipBlanks:=False, Transpose:=False
Columns("AD:AD").Select
Selection.Copy
Columns("U:U").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlPasteSpecialOperationNone, SkipBlanks:=False, Transpose:=False

x = HypMenuVSubmitData()
Sheet75.Range("AE:ZZ").Delete
ActiveSheet.EnableSelection = xlUnlockedCells
ActiveSheet.Protect Password:="abc@1", DrawingObjects:=True, Contents:=True, Scenarios:=False, UserInterfaceOnly:=False, AllowFormattingCells:=False, AllowFormattingColumns:=False, AllowFormattingRows:=False, AllowInsertingColumns:=False, AllowInsertingRows:=False, AllowInsertingHyperlinks:=False, AllowDeletingColumns:=False, AllowDeletingRows:=False, AllowSorting:=False, AllowFiltering:=False, AllowUsingPivotTables:=False
Worksheets(Sname).Cells(5, 2).Select
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False

On Error GoTo ErrL
    Sheet2.Columns("C:D").Clear

        If Target.Row > 4 And Target.Column = 1 And Target.Count = 1 Then
            Grow = Target.Row
            Gcol = Target.Column
            Alastrow = Sheet2.[A65536].End(xlUp).Row
            unname = Sheet75.Cells(Target.Row, Target.Column)
            For i = 2 To Alastrow
                If Sheet2.Cells(i, 1) Like "*" & unname & "*" Then
                    Dlastrow = Sheet2.[D65536].End(xlUp).Row
                    Sheet2.Cells(Dlastrow + 1, 4) = Sheet2.Cells(i, 1)
                    Sheet2.Cells(Dlastrow + 1, 3) = Dlastrow
                End If
            Next i
            
            Dlastrow = Sheet2.[D65536].End(xlUp).Row
            If Dlastrow > 2 Then
            Sheet75.Shapes("列表框 1").ControlFormat.RemoveAllItems
            For i = 2 To Dlastrow
                Sheet75.Shapes("列表框 1").ControlFormat.AddItem (Sheet2.Cells(i, 4))
            Next i
            With Sheet75.Shapes("列表框 1")
                .Visible = msoTrue
                .Top = Target.Top + Target.Height
                .Left = Target.Left
                .Height = Target.Height * 5
            End With
            Sheet75.Shapes("矩形 1").Visible = msoTrue
            Sheet75.Shapes("矩形 1").Left = Sheet75.Shapes("列表框 1").Left
            Sheet75.Shapes("矩形 1").Top = Sheet75.Shapes("列表框 1").Top + Sheet75.Shapes("列表框 1").Height
            Else
                Sheet2.Cells(29, 5) = "*" & Sheet75.Cells(Target.Row, Target.Column) & "*"
                Sheet75.Cells(Target.Row, Target.Column) = Sheet2.Cells(30, 5)
                If Len(Sheet75.Cells(Target.Row, Target.Column)) <= 4 Then
                    Sheet75.Cells(Grow, 1) = ""
                End If
            End If
        Else
            Sheet75.Shapes("列表框 1").ControlFormat.RemoveAllItems
            Sheet75.Shapes("列表框 1").Visible = msoFalse
            Sheet75.Shapes("矩形 1").Visible = msoFalse
        End If
Call tired
Application.EnableEvents = True
Exit Sub
ErrL:
    MsgBox "该公司不存在!"
    Sheet75.Shapes("列表框 1").ControlFormat.RemoveAllItems
    Sheet75.Shapes("列表框 1").Visible = msoFalse
    Sheet75.Shapes("矩形 1").Visible = msoFalse
    Sheet75.Cells(Grow, 1) = ""
    Application.EnableEvents = True
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    If Sheet2.Cells(35, 5) = True Then
        Cancel = True
        Application.MacroOptions Macro:="PasteValue", ShortcutKey:="v"
        Application.StatusBar = "ctrl+v = 粘贴为值"
    End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Row = 1 And Target.Column = 1 Then Exit Sub
    If Target.Row <= 4 Or Target.Column <> 1 Or Target.Count > 1 Then
        Sheet75.Shapes("列表框 1").ControlFormat.RemoveAllItems
        Sheet75.Shapes("列表框 1").Visible = msoFalse
        Sheet75.Shapes("矩形 1").Visible = msoFalse
        Call combo
    End If
End Sub

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-25 13:05 , Processed in 0.021933 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表