Page 1 of 1

[Solved] Close spreadsheet without asking to save

Posted: Thu Aug 17, 2017 7:45 pm
by Tarkovsky
I'm trying to write a macro which will close my Calc without asking me if I want to save it or not after hit the close button.
The solution I have found was:

Code: Select all

Sub Close_Calc()
   ThisComponent.Close(True)
End Sub
It closes my document as expected, but only if I use a button or a shape to call it.
If I associate the same macro to the event: document is going to be closed, it work, but just after that, I get a message saying that my Calc crashed.
How can I fix this?

Re: Close spreadsheet without asking to save

Posted: Thu Aug 17, 2017 8:26 pm
by Zizi64
Try to reset the "Document changed" flag, instead of the forced close during the normal closeing procedure.

Re: Close spreadsheet without asking to save

Posted: Thu Aug 17, 2017 8:48 pm
by Tarkovsky
I tried to call this macro before the Close_Calc macro:

Code: Select all

sub reset_changes
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(9) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Properties.UseUserData"
args1(0).Value = true
args1(1).Name = "Properties.DeleteUserData"
args1(1).Value = false
args1(2).Name = "Properties.Title"
args1(2).Value = ""
args1(3).Name = "Properties.Subject"
args1(3).Value = ""
args1(4).Name = "Properties.KeyWords"
args1(4).Value = ""
args1(5).Name = "Properties.Description"
args1(5).Value = ""
args1(6).Name = "Properties.AutoReload"
args1(6).Value = false
args1(7).Name = "Properties.AutoReloadTime"
args1(7).Value = 0
args1(8).Name = "Properties.AutoReloadURL"
args1(8).Value = ""
args1(9).Name = "Properties.AutoReloadFrame"
args1(9).Value = ""

dispatcher.executeDispatch(document, ".uno:SetDocumentProperties", "", 0, args1())

end sub
But didn't work.
Is that what you meant?

Re: Close spreadsheet without asking to save

Posted: Thu Aug 17, 2017 9:03 pm
by Zizi64
Is that what you meant?
Not.

Code: Select all

Thiscomponent.setModified(false)	

Re: Close spreadsheet without asking to save

Posted: Fri Aug 18, 2017 6:28 am
by Tarkovsky
Oh,, That worked.
Just added your code to run when the event: document is going to be saved is called.
Thank you so much, man!

Re: [Solved] Close spreadsheet without asking to save

Posted: Fri Aug 18, 2017 8:13 am
by Zizi64
Are you using an object inspection now?

If the answer is "not yet": Will you ask us for every property of the every programming objects? :lol: