Page 1 of 1

How to create a new template based document with a Macro?

Posted: Fri Sep 05, 2008 4:23 am
by captorx
Hello! I hope all you are having a great day!
I'm using Writer 2.4 .I created a new template named "HelloWorld.ott". When I want to write a new document using that template, I have to click: File/New Document/Templates/HelloWorld Of course this works quite fine. Now you may think I'm lazy but I have to use that template many times a day and it's a repetitive task, so I'm looking for a faster way to do it. I could set it as Default Template but that's not a solution because I also use other two templates very often.

I'm new to OpenOffice and I really want to get rid of the expensive micromonster. Usually, the main cause of desisting is that I know how to do something with Microsoft Office but I don't know how to do the same with OpenOffice. So I have two questions:

1) It would be great if I could have my HelloWorld templatet in the options of New Document. I mean, just click: File/New/HelloWorld (Just under Text Document Ctrl + N) Do you know a simple way to do this?

2) If 1) is not possible, then I tried by recording a Macro. The idea is to press a button and have a New Writer Document created using HelloWorld template. I tried recording the process of clicking File/New Document/Templates/HelloWorld. But when running the macro, it stops just before I selected HelloWorld template. :roll: I can't figure out the way to modify the script in order to select HelloWorld template. The script text is as follows:

Code: Select all

sub HelloWorld
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 ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:NewDoc", "", 0, Array())


end sub

Many thanks for your answers. I really appreciate your help! :P

Re: How to create a new template based document with a Macro?

Posted: Sat Sep 06, 2008 9:30 pm
by r4zoli
In Andrwe Pitonyak macro doc, contain macro for opening documents from template.

Re: How to create a new template based document with a Macro?

Posted: Sun Sep 07, 2008 5:34 pm
by Villeroy
Ctrl+F11 opens a list of templates to pick from. If you want a particular template to be opened with File>New or Ctrl+N, make it the default template: File>Templates>Organize... pick template [Commands]>Set default.

Re: How to create a new template based document with a Macro?

Posted: Sun Sep 07, 2008 6:45 pm
by Villeroy
I moved this thread to the API forum. Try the following with appropriate constant sPathName:

Code: Select all

Sub openNewDINLetter()
Const sPathName = "/home/andreas/.openoffice.org2/user/template/DIN-Brief.stw"
sURL = ConvertToURL(sPathName)
StarDesktop.loadComponentFromURL(sURL,0,"_default",Array())
End Sub