[Solved] Close spreadsheet without asking to save

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Tarkovsky
Posts: 29
Joined: Fri Jun 30, 2017 9:17 am

[Solved] Close spreadsheet without asking to save

Post 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?
Last edited by Tarkovsky on Fri Aug 18, 2017 6:28 am, edited 1 time in total.
OpenOffice 4.1.3 on Arch Linux
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Close spreadsheet without asking to save

Post by Zizi64 »

Try to reset the "Document changed" flag, instead of the forced close during the normal closeing procedure.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Tarkovsky
Posts: 29
Joined: Fri Jun 30, 2017 9:17 am

Re: Close spreadsheet without asking to save

Post 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?
OpenOffice 4.1.3 on Arch Linux
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Close spreadsheet without asking to save

Post by Zizi64 »

Is that what you meant?
Not.

Code: Select all

Thiscomponent.setModified(false)	
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Tarkovsky
Posts: 29
Joined: Fri Jun 30, 2017 9:17 am

Re: Close spreadsheet without asking to save

Post 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!
OpenOffice 4.1.3 on Arch Linux
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Solved] Close spreadsheet without asking to save

Post 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:
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Post Reply