OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

save and close document macro

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
Tommy27
OOo Advocate
OOo Advocate


Joined: 18 Nov 2006
Posts: 302

PostPosted: Sun Jul 24, 2011 4:57 am    Post subject: save and close document macro Reply with quote

very simple macro that saves current OOo document and close it.

I assigned it to the "Esc" key


Code:
sub SaveAndClose
dim document   as object
dim dispatcher as object
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:Save", "", 0, Array())
ThisComponent.close(True)
end sub



I found it useful as an "auto-save" workaround when closing a document without manually selecting the "Yes" or "No" saving dialog window
Back to top
View user's profile Send private message
DrBones
General User
General User


Joined: 07 Nov 2008
Posts: 15
Location: Long Island, NY

PostPosted: Fri Jul 29, 2011 3:19 pm    Post subject: Reply with quote

Hey Tommy27

What would you add to the code to "save the current record" for writer forms?

Thanks!

DrBones
Back to top
View user's profile Send private message
Tommy27
OOo Advocate
OOo Advocate


Joined: 18 Nov 2006
Posts: 302

PostPosted: Sun Jul 31, 2011 4:38 am    Post subject: Reply with quote

writer forms?

I don't understand... what do you mean exactly?
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Sun Jul 31, 2011 9:10 am    Post subject: Reply with quote

Hello

For saving data in a form use the basetools of Benitez.
and start a new thread this is off topic here

Romke
Back to top
View user's profile Send private message
tobski
Newbie
Newbie


Joined: 18 Sep 2012
Posts: 4
Location: Philippines

PostPosted: Sat Oct 06, 2012 2:05 am    Post subject: Push Button save record and Close form Reply with quote

I just copy the code:
sub SaveAndClose
dim document as object
dim dispatcher as object
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:Save", "", 0, Array())
ThisComponent.close(True)
end sub
and I get the below email.

Basic: Runtime Error
An exception occurred
Type:com.sun.star.util.closeVetoException Message:.

How I can make a push button where I can save record before closing the form.
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Tommy27
OOo Advocate
OOo Advocate


Joined: 18 Nov 2006
Posts: 302

PostPosted: Sun Nov 11, 2012 10:39 am    Post subject: Reply with quote

@tobski

that macro is intended for Writer documents.
it doesn't work in Base
Back to top
View user's profile Send private message
AlwynWellington
General User
General User


Joined: 06 Dec 2013
Posts: 6

PostPosted: Mon Dec 09, 2013 11:48 am    Post subject: close Writer file from with a Calc macro Reply with quote

From JohnV (forum moderator)
and working with a Calc macro, I have learnt to:

1) create a new/open existing Writer document
2) copy text to the clipboard from a calc cell
3) paste formatted text to the Writerdocument
4) give the Writer document a new name and save it

Most of this uses dispatcher .uno:command calls.

Relative to this thread:

I would like to learn how to close the Writer file
from within the Calc macro.
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Mon Dec 09, 2013 3:25 pm    Post subject: Reply with quote

For an existing file:
ThisComponent.Store
ThisComponent.Close(true)

For a new Writer file:
filename = "MyFile.odt"
url = ConvertToURL("C:\SomeDirectory\" & filename)'INSERT YOUR DESIRED DIRECTORY PATH.
ThisComponent.StoreAsURL(url,Array())

Note that with the macro we have been working on you want to save the Writer document and not the Calc one so you should use:
NewDoc.StoreAsURL(url,Array())
I say this because I don't know where you have stored the macro. If inside the Calc doc. then ThisComponent will refer to it but if outside the Calc doc. then ThisComponent will refer to the last active document.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group