Michael Jones
New Member
- Joined
- Jul 15, 2014
- Messages
- 19
Following an excel upgrade to excel 2016 640bit I now receive a compile error stating "The code in this project must be updated for use on 64-bit systems..." I am using the following vba which locks cells after an entry is made. I need the code to work on both 32-bit and 64-bit systems but cannot work out where to add the "Ptr Safe" statement (and any other amendments required) to enable this. I would be very grateful if someone could suggest an amendment to my code to enable this vba to run successfully, as I am very much a vba newbie.
Code:
Option Explicit
Private Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) As Long
Private Declare CloseClipboard Lib "User64" () As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub ' unprotect only when a single cell is selected
If Sheets("Switch").Range("AutoExpand") Like "Disabled" Then Exit Sub
Dim Tbl As ListObject, Off As Integer, ExitCode As Label
Dim TblFirstRow As Long, TblFirstColumn As Integer
Dim FirstRowAllowed As Long
On Error GoTo ExitCode
Off = 0: If Target.Row > 1 Then Off = -1
Set Tbl = ActiveSheet.ListObjects(1)
TblFirstRow = Tbl.HeaderRowRange.Row
TblFirstColumn = Tbl.HeaderRowRange.Cells(1, 1).Column
OpenClipboard 0 ' when a macro runs, usually the clipboard is emptied; opening the clipboard will preserve whatever you have in there;
FirstRowAllowed = TblFirstRow ' the table will be unprotected if the user selects a cell from this row down
If Target.Row >= FirstRowAllowed And Target.Row <= Tbl.ListRows.Count + TblFirstRow + 1 And _
Target.Column <= Tbl.ListColumns.Count + TblFirstColumn And _
Target.Cells.Offset(Off, 0).Locked = False Then
Unprotect
CloseClipboard
Else
GoTo ExitCode
End If
Exit Sub
ExitCode:
Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False, UserInterfaceOnly:=True, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingRows:=True, AllowSorting:=True, _
AllowFiltering:=True, AllowUsingPivotTables:=True
CloseClipboard
End Sub
Last edited by a moderator: