Apologies, to save space in this thread, I used a bit of “shorthand” explaining what I am trying to achieve.
- As mentioned, I compile my workbook with XLS Padlock and then create setup with Paquet Builder.
- In Paquet Builder I specify the programs folder as default destination folder where a folder (MyFolder) will be created. The files MyFile.EXE, MyFile.XLSC and .DAT files will be stored inside this folder. The path I specify in Paquet Builder is: %PROGFILEDIR%\MyFolder\
- When I install my program on my computer with Paquet Builder Setup (first time), only the .EXE file is initially installed (no XLSC file visible yet).
- All ribbons and toolbars in Excel are disabled (condition set in XLS Padlock). I programmatically, with a command button on a user form, save the secured (.XLSC) workbook.
- In my code, I do not do a “Save As” with a pre-defined file path and pre-specified file name like in your example (“d:\my documents\my save.xlsc”).
- Because I intend distributing my program to other users and the fact that my program will be installed on different computers, I had to adapt my save procedure to work on any computer.
- The code snippets I found in the User Guide were fully copied into modules in my project, exactly as they appear in the User Guide. My own “save” procedure is also in a module and is invoked by using a combination of the results obtained from the “User Guide” codes/modules (i.e. GetEXEFilename(), PathToFile(Filename As String), GetSecureWorkbookFilename() and SaveSecureWorkbookToFile(Filename As String)).
- Explanation of my save module (code):
My code to save encrypted workbook (also to accommodate first time save):
Public Function SaveWorkbookToFolder() 'My own module
Dim XLSPadlock As Object
Dim ThisFileName As String
Dim FileNameArray() As String
Dim BaseFileName As String
Set XLSPadlock = Application.COMAddIns(“GXLSForm.GXLSFormula”).Object
ThisFileName = GetEXEFilename
FileNameArray = Split(ThisFileName, “.”)
BaseFileName = FileNameArray(0) & “.xlsc”
On Error GoTo Err
If Dir((PathToFile(BaseFileName))) <> “” Then
SaveSecureWorkbookToFile GetSecureWorkbookFilename
Else
SaveSecureWorkbookToFile PathToFile(BaseFileName)
End If
Exit Function
Err:
BaseFileName = “”
End Function
ThisFileName =
GetEXEFilename = MyFile.exe -
(User Guide code)
FileNameArray = Split(ThisFileName, “.”) = MyFile
BaseFileName = FileNameArray(0) & “.xlsc” = MyFile.xlsc
Your example: (“d:\my documents\my save.xlsc”)
PathToFile = (“d:\my documents") -
(User Guide code)
PathToFile(BaseFileName) = (“d:\my documents\my save.xlsc”) - (My code for first time save)
GetSecureWorkbookFilename = (“d:\my documents\my save.xlsc”) -
(User Guide Code)
SaveSecureWorkbookToFile GetSecureWorkbookFilename = (save protected workbook to [“d:\my documents\my save.xlsc”] for all subsequent saves -
(User Guide Code))
I fully understand the code snippets you have provided (thanks). I have incorporated User Guide codes in my module “SaveWorkbookToFolder()” which I designed to overcome a “first time save”, as the .xlsc file does not exist yet after Paquet Builder installs my program (for the first time) with SetUp.
My question remains:
In my “SaveWorkbookToFolder()” module, should I use,
Set XLSPadlock = Application.COMAddIns(“GXLSForm.GXLSFormula”).Object
or
Set XLSPadlock = Application.COMAddIns(“GXLS.GXLSPLock”).Object…???
Thank you
Ps. The code in my module works 100% and gives the correct result (tested)…it is just that I don’t know whether I should use (“GXLSForm.GXLSFormula”).Object or (“GXLS.GXLSPLock”).Object?