excel vba代码适用于2010(32位),但不适用于2016(64位)

时间:2018-03-15 11:48:39

标签: excel-vba vba excel

我是这个论坛的新手,需要一些帮助。我最近从Excel中的32位Excel 2010迁移到了64位2016和2010年的32位宏启用excel工作簿不再在2016年正确运行任何宏。我理解底层问题但不知道如何更新vba代码。任何想法都会受到高度赞赏吗?

'更改密码" PASSWORD"到你的密码(包括撇号)     Const PW =" ***"     Sub Auto_Open()

ActiveWorkbook.Protect _`enter code here`
Password:=PW

For Each sht In ActiveWorkbook.Sheets

sht.Protect _
Password:=PW, _
DrawingObjects:=True, _
Contents:=True, _
Scenarios:=True, _
UserInterfaceOnly:=True, _
AllowFiltering:=True

Next sht
End Sub
Private Sub Protect_Sheet()

ActiveSheet.Protect _
Password:=PW, _
DrawingObjects:=True, _
Contents:=True, _
Scenarios:=True, _
UserInterfaceOnly:=True, _
AllowFiltering:=True

End Sub
Private Sub Unprotect_Sheet()

ActiveSheet.Unprotect _
Password:=PW

End Sub
Sub Insert_Row()

If ActiveSheet.Name <> "Detail" Then
Exit Sub
Else
End If

Unprotect_Sheet
'Clear filters
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0

'Select and copy standard row formulas/formats
Range("Row_Std").Select
Selection.Copy

'Find next available row and paste standard row
Range("B4").Select

If Range("B5").Value = "" Then
Range("A5").Select
Else
Selection.End(xlDown).Offset(1, -1).Select
End If

ActiveSheet.Paste

ActiveCell.Select
ActiveCell.Copy
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.Offset(0, 1).Select
ActiveCell.Copy
ActiveCell.PasteSpecial (xlPasteValues)

Application.CutCopyMode = False
Range("B4").Select

'Protect sheet
Protect_Sheet

End Sub
Sub Delete_Row()

If ActiveSheet.Name <> "Detail" Then
Exit Sub
Else
End If

Calculate

If Range("B1").Value = 0 Then
Exit Sub
Else
Unprotect_Sheet

On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0

Range("C4").AutoFilter Field:=3, Criteria1:="Y"
Range("C5:" & Range("C4").End(xlDown).Address).Select
If Range("B1").Value > 1 Then
    Selection.SpecialCells(xlCellTypeVisible).Select
Else
End If
Selection.EntireRow.Delete Shift:=xlUp

On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0

End If

If Range("A5").Value = "" Then
Else
Range("B2").Copy
Range("B5:" & Range("B4").End(xlDown).Address).PasteSpecial (xlPasteAll)
End If

Application.CutCopyMode = False
Range("B4").Select
Protect_Sheet
End Sub
Sub Clear_Filter()

If ActiveSheet.Name <> "Detail" Then
Exit Sub
Else
End If

On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0

End Sub

0 个答案:

没有答案