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

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
captorx
Posts: 6
Joined: Fri Sep 05, 2008 1:10 am

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

Post 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
OOo 2.4.X on MS Windows Vista + Ubuntu
User avatar
r4zoli
Volunteer
Posts: 2882
Joined: Mon Nov 19, 2007 8:23 pm
Location: Budapest, Hungary

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

Post by r4zoli »

In Andrwe Pitonyak macro doc, contain macro for opening documents from template.
AOO 4.0 and LibO 4 on Win 8
Hungarian forum co-admin
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post 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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post 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
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply