Saving with vba code

I have a question please:

(Im a new user in xls padlock).

I’m trying to to create a simple save in my workbooks, my goal is to create a situation that all of the saving event’s will be only with my vba code and without your “save as” dialog box.

so I understand that I need to add one of your extension code to do it, so I add this code:

Public Function SaveSecureWorkbookToFile(Filename As String)
On Error GoTo Err
Set XLSPadlock = Application.COMAddIns(“GXLS.GXLSPLock”).Object
SaveSecureWorkbookToFile = XLSPadlock.SaveWorkbook(Filename)
Exit Function
Err:
SaveSecureWorkbookToFile = ""
End Function

but it’s still does not saving, maybe because i’m not using the Filename variable right.

what I need to do please ?

maybe there is a “workbook example” that I can learn from

I have one more question but I will post it in a new topic

thanks

How do you call the SaveSecureWorkbookToFile function?

For instance, you can use:

Sub TestSave()
SaveSecureWorkbookToFile ("d:\my documents\my save.xlsc")
End Sub

thanks for answer

I don’t understand why I need to inform the active workbook location path ?

maybe I wasnt clear, all I want to do, is that the THISWORKBOOK.SAVE will work, in my workbooks this line of code dont save my workbooks.

thanks again

Actually, it’s how XLS Padlock works. THISWORKBOOK.SAVE works, but the file is not written to the disk.

If you want the file to be saved in encrypted form programmatically, you must call SaveSecureWorkbookToFile and tell where to save.
You can also get the path to the folder that contains the EXE with VBA API of XLS Padlock.

Ok,

I tried now this exact code:

Sub SaveItNowTest()
Call SaveSecureWorkbookToFile(ThisWorkbook.Path)
End Sub

Public Function SaveSecureWorkbookToFile(Filename As String)
On Error GoTo Err
Set XLSPadlock = Application.COMAddIns(“GXLS.GXLSPLock”).Object
SaveSecureWorkbookToFile = XLSPadlock.SaveWorkbook(Filename)
Exit Function
Err:
SaveSecureWorkbookToFile = ""
End Function

still not saving :frowning:

ThisWorkbook.Path is not correct because it will be just a folder path, there is no filename. Try to add a filename.

Thanks for answer

let say that my excel document is on the desktop, I tried now in the “fileName” variable to use THISWORKBOOK.FULLNAME (don’t work), THISWORKBOOK.NAME (don’t work).

please tell me what to do step by step because I think I tried everything

TNX

Try

Sub SaveItNowTest()
Call SaveSecureWorkbookToFile(ThisWorkbook.Path & “myworkbook.xlsc”)
End Sub

still don’t working :confused:

I can’t distribute my workbook’s without this function.

Actually I answered too fast. ThisWorkbook.Path is actually incorrect because it points to a virtual folder. Thus it won’t be accessible.
You should try:

Sub SaveItNowTest()
On Error GoTo Err
Set XLSPadlock = Application.COMAddIns(“GXLSForm.GXLSFormula”).Object
PathToFile = XLSPadlock.PLEvalVar(“EXEPath”) & "myworkbook.xlsc"
Call SaveSecureWorkbookToFile(PathToFile)
End Sub

I’m sorry but it still doesn’t work.

Try this code instead. Here is also a workbook in Excel 2013 format:
http://demo.ovh.eu/en/0f860cea19e92dbfc6e11d744246a3a8/

Public Function SaveSecureWorkbookToFile(Filename As String)
On Error Resume Next
Set XLSPadlock = Application.COMAddIns("GXLS.GXLSPLock").Object
SaveSecureWorkbookToFile = XLSPadlock.SaveWorkbook(Filename)
End Function

Sub SaveItNowTest()
On Error Resume Next
Set XLSPadlock = Application.COMAddIns("GXLSForm.GXLSFormula").Object
PathToFile = XLSPadlock.PLEvalVar("EXEPath") & "myPREVIOUSworkbook.xlsc"
SaveSecureWorkbookToFile (PathToFile)
End Sub

OK, there is same progress, because until now, every time when I tried if its work, I tried with and without checking the box of "do not prompt users for filename when saving, and until now both options was not working, but now, with the workbook you send, it’s saving only with the uncheck of the “do not prompt…” function, and actually I need the checked option - because, now when I open the saved exe workbook it’s asking me “what to open” - and I don’t need this msgbox at all.

more ideas ?

Which message box? Do you mean the dialog box that lets you choose which save to open?

yes. this dialog box

Without this dialog box, you can’t load an encrypted workbook so SaveSecureWorkbookToFile is useless in your case.
If you wish to save normal workbooks (without encryption), you can see 9.6 Allow saving non encrypted workbooks in the user guide.

but what if I do not want to let my end user the choice to select to “go back” ?

let say you are selling an “excel invoice application” (and I have something like that - very sophisticated) that you cant let the end user to go back after he produced an invoice.

this option (to not let the end user the choice) is very critical for me, in a lot of my excel application’s

TNX

I understand, but do you still want to load changes made back by the user?

I’m not sure what you mean by that , please expand…

If you save an encrypted workbook, the sole way to load it back is through the dialog box. There is no API in XLS Padlock to load an encrypted workbook through VBA. On the contrary, if you don’t want to deal with encrypted workbooks, you can still use normal load/save VBA code from Excel.