[Solved] Close spreadsheet without asking to save

Creating a macro - Writing a Script - Using the API

[Solved] Close spreadsheet without asking to save

Postby Tarkovsky » Thu Aug 17, 2017 7:45 pm

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   Expand viewCollapse view
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
Tarkovsky
 
Posts: 29
Joined: Fri Jun 30, 2017 9:17 am

Re: Close spreadsheet without asking to save

Postby Zizi64 » Thu Aug 17, 2017 8:26 pm

Try to reset the "Document changed" flag, instead of the forced close during the normal closeing procedure.
Tibor Kovacs, Hungary; LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.5; AOO4.1.6
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.
User avatar
Zizi64
Volunteer
 
Posts: 8225
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Close spreadsheet without asking to save

Postby Tarkovsky » Thu Aug 17, 2017 8:48 pm

I tried to call this macro before the Close_Calc macro:

Code: Select all   Expand viewCollapse view
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
Tarkovsky
 
Posts: 29
Joined: Fri Jun 30, 2017 9:17 am

Re: Close spreadsheet without asking to save

Postby Zizi64 » Thu Aug 17, 2017 9:03 pm

Is that what you meant?

Not.

Code: Select all   Expand viewCollapse view
Thiscomponent.setModified(false)   
Tibor Kovacs, Hungary; LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.5; AOO4.1.6
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.
User avatar
Zizi64
Volunteer
 
Posts: 8225
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Close spreadsheet without asking to save

Postby Tarkovsky » Fri Aug 18, 2017 6:28 am

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
Tarkovsky
 
Posts: 29
Joined: Fri Jun 30, 2017 9:17 am

Re: [Solved] Close spreadsheet without asking to save

Postby Zizi64 » Fri Aug 18, 2017 8:13 am

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; LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.5; AOO4.1.6
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.
User avatar
Zizi64
Volunteer
 
Posts: 8225
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 6 guests