Stroring to encrypted files by unexperienced users is a frequent cause of data loss. No remedy then!
If you feel sure to know what you are doing, you can use the code below to start. (LibreOffice Basic isn’t “VBA”.)
Sub saveEncrypted(Optional pPwd As String)
If IsMissing(pPwd) Then pPwd = "encrypted"
doc = ThisComponent
cURL = doc.URL
If (cURL="") OR NOT (FileExists(cURL)) Then
Print "A complete existing URL is needed in the example."
REM Of course, the URL to store to can be any URL the calling
REM user has the right to write to.
Exit Sub
End If
Dim saveEncryptedArgs(0) As New com.sun.star.beans.PropertyValue
saveEncryptedArgs(0).Name = "Password"
saveEncryptedArgs(0).Value = pPwd
doc.storeAsURL(cURL, saveEncryptedArgs)
doc.close(True)
End Sub
My extra problem is to understand for what reason this should be done by a “macro”.