« OpenOffice! The Musical! (Friday fun) | Main | Un-displaying the grid lines in OpenOffice.org Calc »

April 14, 2008

Attaching a Document (Including Templates) to an OpenOffice Menu Item or Toolbar

This is huge. Thanks to TerryJ on the users@openoffice.org alias for pointing the way.

So you're an IT director. You want to make things easy for your users (and thus easy for your team so they need to answer fewer questions). One way to make things very easy and simple for your users is to create templates.

  • Create a template that has no page number on the first page and a page number, starting at 1 or 2, on the 2nd page. (A user could create this but it involves understanding styles and is just way more difficult than it needs to be.)
  • Create a template that has a watermark background like Confidential.
  • Create a template that has whatever characteristics are needed for a department's tasks.

Now, you could create a template and just set it as the default template so that users get that template when they choose File > New. But if you have multiple documents they need to make, you probably don't want to do that. Or you can do that, but you have more than one template you want to offer.

You could just put your templates in a nice centralized location for your users. However, some users don't view it as all that convenient or obvious to choose File > New > Templates and Documents, the pick the right category and the right template.

Here's how to make it easy, and thus likely, for users to use the templates you provide for them, and thus for them to not even enounter problems, or encounter tasks that are harder than they need to be.

Make a menu and attach templates to menu items on that menu.

Now, this means more up-front work for you, but then it's done.

A)  Make your templates and put them in a central network location. Be sure they're in template format, not document format.

B. Create a new menu.
Choose Tools > Customize, click the Menu tab, click New, then name it and click OK.

Attach1

Attach2

C. Now you just need to add menu items that point to the templates.

First, create the macro.

1. Choose Tools > Macros > Organize Macros > OpenOffice.org Basic.
2. This window will appear. The macro I already created is listed there. In this example I'll create another one that does the same thing.

Macro1

3. In the Macro Name field, type the macro name like OpenTemplate.

4. Click New.
Macro2

5. What you now see in the macro editing area will depend on what was there last. I'm not incredibly familiar with the macro window but I know that what I did worked ;> so you should be able to follow these directions successfully.

Macro3

Regardless of what else is in there, you want to have the following. Find the part that says 
Sub macroname
End sub

and put your macro in the middle.  Leave all the other macros that are there.

6. Now you want to write the following macro. There are variations here but this is what I did that worked.

I show an example first, then syntax.

Example


Sub OpenTemplate

Dim sUrl as String

sUrl = "file:///C:/openofficemacros/sampletemplate.ott" ' note you must use url format
If NOT FileExists( sUrl ) Then : Msgbox( "No file named " & sUrl ) : Exit sub : End If
StarDesktop.loadComponentFromURL( sUrl, "_blank", 0, Array() )

End Sub

Now the syntax


Sub name of macro

Dim sUrl as String

sUrl = "file:///path to file you want to open"'    ' note you must use url format
If NOT FileExists( sUrl ) Then : Msgbox( "No file named " & sUrl ) : Exit sub : End If
StarDesktop.loadComponentFromURL( sUrl, "_blank", 0, Array() )

End Sub

 
7. Click the Save icon and close the macro.
Macrosavesmall

8. If you choose Tools > Macros > Organize Macros > OpenOffice.org Basic again, you'll see the macro name. Here the original one I wrote and the one I added for this example are both shown.

Macro5_showboth

9. From here, you can either:
Select the macro to use and click Assign
OR
Close the window, then choose Tools > Customize, and in the Menus tab,  select the menu you created.
Macroadditem1

10. Click Add next to the empty list for menu items

11. In the window that appears, expand the Macros category at the bottom, and select the macro you wrote.
Macroadditem2

12. Click Add.

13. Close the window.

14. Select the item, click and hold down on Modify.
Rename1

15. In the window that appears, rename the item however you like and click OK.
Rename2

16. Click OK in the Customize window.

17. Now choose the menu and the menu item.

Choosefrommenu

18. The document you created appears. If you created it in template format, then it will be an untitled copy of the document.

Macroadditem4

D. Copy the configuration to other computers.

1. Copy the macro to the same location on other computers.

2. Copy the configuration file where the menu and menu items are stored to the same location on other computers. It's called menubar.xml; there are several depending on what the menu is for. Here's where it is on Windows for a Writer menu; for Calc it would be scalc\menubar\menubar.xml, and so on.

<openofficeinstalldir>\soffice.cfg\modules\swriter\menubar\menubar.xml

Here's what the content looks like in the menubar.xml file.

<menu:menu menu:id="vnd.openoffice.org:CustomMenu1" menu:label="Use These Templates">
  <menu:menupopup>
   <menu:menuitem menu:id="vnd.sun.star.script:Standard.Module1.OpenTemplate?language=Basic&amp;location=application" menu:helpid="vnd.sun.star.script:Standard.Module1.OpenTemplate?language=Basic&amp;location=application" menu:label="Use this for meeting minutes"/>
  </menu:menupopup>
</menu:menu>

See this link for the original explanation.


Traininglogo




TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341cdb1753ef00e551a6622b8833

Listed below are links to weblogs that reference Attaching a Document (Including Templates) to an OpenOffice Menu Item or Toolbar:

Comments

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment