How do you terminate a save process from a macro?

i will try and explain this the best way I can.

In my spreadsheet, I have a macro that is triggered when the user clicks the save button or clicks ctrl(cmd for mac)+s. I have done this mapping by going to tools → customize.

In certain scenarios, I need to give the user an option to save the file as new file. That is if the user clicks save and certain conditions are met, ( a major change in price for ex) the macro which gets triggered before saving will give the user an option to save our file as a new one. However the changes also get saved in the old document as the user has already pressed save.

Is there any way to kill the first save process using libre basic? If not I will need to think of a workaround for my scenario.

Edit: My LO version is 6.3 on macos 10.13.6

This question is very similar to yours. Perhaps the answer to your question will be the same?

It indeed is similar to that question. Nevertheless, thanks for giving an answer.

Usually they do it like this:

Function onSave(Optional oEvent As Variant) As Boolean 
Dim newName As String 
	onSave = False	' If function return this value then "standard Save" will done '
	If <Condition_for_SaveAs> Then 
		newName = InputBox("New Name","Save as copy",ConvertFromURL(ThisComponent.getURL()))
		ThisComponent.StoreAsURL(ConvertToURL(newName),Array())
		onSave = True ' Now the event processing will stop and the standard Save will not work '
	EndIf
End Function

Just for clarification.

storeAsURL will change current document location while saving to the new location. I.e., after this call, all following simple "Save"s will go to the new place. (So “Save as copy” message in the dialog might be somewhat misleading.)

storeToURL saves the data to a copy, but keeps the open document’s path as it was before.

See com.sun.star.frame.XStorable documentation.

Thanks for the help @JohnSUN. So, from your answer, I gather that when the return value is true, it signals to LO that the save has already happened.

@mikekaganski, I was aware of this before, but thanks for clarifying anyways.

@JohnSUN I have realized that I have not understood fully what’s going on here, although your suggestion has answered my question. Can you share some reference material which explains this well. I have scoured the internet and I was unable to find any material

@squireash Ah, unfortunately now I cannot give a link. Perhaps I found this information on this page, but it is not available now

Internet never forgets! :wink:

Thanks @mikekaganski!. Unfortunately, I was wrong - the trick of assigning a Boolean return value to an event handler was not described on this page.