Dear experts
I've been working for the last few months on a vba project that basically generates a technical report of many pages long, distributing imported data, populating tables etc. in one click. It's quite an important project and I have already spent many months on it, trying to automate our work.
Problem is that not only I want to keep the source code completely safe from my colleagues and the management, but for now I would like to let everyone but me only use it without actually owning it or running it independently.
Therefore, the file under development should not contain any of the code I have built, but make it somehow load it upon use and unload it afterwards.
The source code should be totally absent from the file under development and saved in another, hidden location in our common file server, where all colleagues have access.
So I have thought of this: Instead of the file (technical report) under development to run directly the populating macro (which I have built already), the file would use an intermediate file which basically contains the real path to the hidden source code. The intermediate file would be encrypted in binary code, preventing anyone from reading the target's location.
If my research is correct, a safe encryption of the intermediate file can be accomplished by using Excel and the special software from vbacompiler.com.
In summary:
Let word file "A" be the file under development.
Let excel file "B" be the intermediate file for redirecting purposes.
Let word file "C" be the file containing the actual populating code.
The user opens first of all "A" and clicks a button ("A" must remain open) -> a marco in "A" triggers a specific macro in "B" -> a macro in "B" triggers a specific macro in "C" -> "C" can read and alter the contents of "A" -> when finished, "A" should remain open and "B" and "C" should close.
'corresponding Word and Excel Object libraries have been activated in all cases
"A"
Private Sub Label4_Click()
Dim objExcel As Object
Dim wbExcel As Excel.Workbook
Set objExcel = CreateObject("Excel.Application")
Set wbExcel = objExcel.Workbooks.Open("C:\testvba\B.xlsm")
With objExcel
' .Visible = True
.Application.Run ("thisworkbook.function22")
End With
wbExcel.Close SaveChanges:=False
objExcel.Quit
Set objExcel = Nothing
Set wbExcel = Nothing
End Sub
"B"
Sub function22()
Dim objWord As Object
Dim wbWord As Word.Document
Set objWord = CreateObject("Word.Application")
Set wbWord = objWord.Documents.Open("C:\Users\C.docm")
With objWord
'.Visible = True
.Application.Run ("thisdocument.task22")
End With
wbWord.Close SaveChanges:=False
objWord.Quit
Set objWord = Nothing
Set wbWord = Nothing
End Sub
"C"
Private Sub task22()
Documents("A.docm").Activate
'rest of code…
end sub
With all the above being said, I currently cannot tell "C" file to make "A" the active document, because my source code contains a lot of lines staring with "ActiveDocument.".
I get a pop-up error "'run-time' 440:Method 'run' of object_Application failed." in the line of "A": .Application.Run ("thisworkbook.function22")
Perhaps this is happening because the macro is still running in "A", which begins the process in the first place?
Is the method i have thought for protection safe and feasible, or do you have anything better to suggest?
Thank you in advance.