PDA

View Full Version : Solved: Hiding the source code...



Ricardovp
02-21-2005, 10:45 AM
Hi all!

I am new here in this f?rum, and I need a little help...

I need to hide the source code of a Macro from the user, but i dont know how to do it :banghead: . somebody can help me?

Thanks

Howard Kaikow
02-21-2005, 11:02 AM
Hi all!

I am new here in this f?rum, and I need a little help...

I need to hide the source code of a Macro from the user, but i dont know how to do it :banghead: . somebody can help me?

Thanks

You can password protect the project.
This will prevent most users from seeing the code.
However, it is trivial to bypass password protection, so if you really wanna protect your code, you need to compile the code into a VB 6 DLL and then use a minimal amount of code within the actual Word template.

For example, the code below is a module in my Word 2003 Normal template. The real code is in a VB 6 DLL that has the WordVBNormal class.

Developing such classes has the added advantage of providing an opportunity to re-organize my code and eliminate duplicate code.

For example, I must have at least umpteen different subs for registering/unregistering DLLs. Today, cowinkidentally, I finished creating a class that does everyting I need for (un)registering DLLs, so I'll register the DLL and get rid of the other code.


Option Explicit
Public clsWordVBNormal As WordVBNormal

Public Sub AutoClose()
SetupClass
clsWordVBNormal.AutoClose
End Sub

Public Sub AutoExec()
' Runs only when global
SetupClass
clsWordVBNormal.AutoExec
End Sub

Public Sub AutoExit()
SetupClass
clsWordVBNormal.AutoExit
End Sub

Public Sub AutoNew()
SetupClass
clsWordVBNormal.AutoNew
End Sub

Public Sub AutoOpen()
SetupClass
clsWordVBNormal.AutoOpen
End Sub

Private Sub SetupClass()
Dim docTemp As Word.Document
If clsWordVBNormal Is Nothing Then
If Documents.Count = 0 Then
Set docTemp = Documents.Add(Visible:=vbFalse)
End If
Set clsWordVBNormal = New WordVBNormal
clsWordVBNormal.SetClass Word.Application
If Not (docTemp Is Nothing) Then
docTemp.Close
Set docTemp = Nothing
End If
End If
End Sub

Ricardovp
02-21-2005, 11:17 AM
Hi Howard!

Thanks for the Tip!!!

How can I password protect the project?? I dont know the Word an VBA very well, actually it is my first project in VBA... its will work just to complement the program that I develop...

Thanks

Paleo
02-21-2005, 11:50 AM
Hi Ricardo,

just right-click Project(Documento1) then select Protect and "Bloquear projeto para exibi??o" (Block project for exibition). Insert and confirm a password. Ok its done.

Ricardovp
02-21-2005, 12:00 PM
Thanks Paelo!
:beerchug:

Paleo
02-21-2005, 12:06 PM
You are welcome. If sometime you rather you may even ask questions in portuguese in our non-english area.