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

Creating a macro - Writing a Script - Using the API

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

Postby captorx » Fri Sep 05, 2008 4:23 am

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   Expand viewCollapse view
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
captorx
 
Posts: 6
Joined: Fri Sep 05, 2008 1:10 am

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

Postby r4zoli » Sat Sep 06, 2008 9:30 pm

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
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?

Postby Villeroy » Sun Sep 07, 2008 5:34 pm

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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26854
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby Villeroy » Sun Sep 07, 2008 6:45 pm

I moved this thread to the API forum. Try the following with appropriate constant sPathName:
Code: Select all   Expand viewCollapse view
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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26854
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 3 guests