« Finally the truth! and just as quickly gone... | Main | Working with Task and Assignment Fields VBA »

Securing Your MS Project Files and Macro Code

Securing your project file or keeping things secret inside it seems to be a perpetual topic. There are some parts of the file that you can secure fairly easily, but if you encrypt or remove any of the data that is needed for project to calculate you will have problems. That said, here is some simple code for encrypting the date entered in the Text1 field:


Sub encodeTextField1()
Dim t As Task
Dim ts As Tasks
Dim tempString As String
Dim key As Long
Set ts = ActiveProject.Tasks
key = InputBox("Enter Key between 1 and 256")
For Each t In ts
If Not t Is Nothing Then
tempString = t.Text1
eNcode tempString, key
t.Text1 = tempString
End If
Next t
MsgBox "Done"
End Sub


Private Sub eNcode(ByRef eText As String, ByRef eKey As Long)
Dim bData() As Byte
Dim lCount As Long
bData = eText
For lCount = LBound(bData) To UBound(bData)
bData(lCount) = bData(lCount) Xor eKey
Next lCount
eText = bData
End Sub

What this macro does is prompt the user for a key which is used with the XOR operator to encrypt the data. You can read more about how this works here. If you like, you can expand on this and use a more sophisticated algorithm, but this should stop most casual readers from decrypting your data unless they have read this article.

The problem with this approach is that the algorithm used for encryption is exposed whenever anyone hits ALT+F11 and views the macro code. You can avoid this by keeping the code in your global.mpt file. However, that would prevent any others from being able to encrypt the data. So we need to take a second step and protect the macro code itself.

  1. From the VBA editor, right-click on the module where the code is located.
  2. From the shortcut menu, select VBAProject Properties (If it is in your global.mpt file it will be ProjectGlobal Properties)
  3. On the Protection tab, check the Lock Project For Viewing check box.
  4. Enter a password and verify it in the boxes at the bottom of the tab.
  5. Click OK.

Now your code is protected. I should warn you that even this is not secure. It is possible to break the password that you have used to protect the macro and with knowledge of the algorithm you used it may be possible for someone to break the password which you have used to encrypt the data, so if something is really secret don't even bother to do this, just keep the file locked somewhere secure and don't share it. But for casual users this should be sufficient to keep them from snooping around.

RELATED POSTS

About

The previous article is Finally the truth! and just as quickly gone....

The next article is Working with Task and Assignment Fields VBA.

Current articles are in the main index page and you can find a complete list of articles in the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.34