Ask Your Question
1

Capturing Title in Writer Document Saved Filename. [closed]

asked 2017-09-04 17:20:45 +0100

Lady Fitzgerald gravatar image

Word will automatically use the first line of text in a document, generally the title, up to the first punctuation, such as a period or apostrophe, or carriage return as the suggested title of the documents filename when saving a document for the first time. Is it possible to do that in Writer?

I'm currently copying the title of a new document before clicking on Save for the first time, then pasting it into the filename box. It works just fine but it's a bit annoying to have to do it every time I save a new document for the first time (yes, I'm lazy and spoiled by Word).

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2021-02-14 21:40:11.072764

2 Answers

Sort by » oldest newest most voted
0

answered 2018-01-22 01:40:14 +0100

librebel gravatar image

updated 2018-01-25 08:39:38 +0100

Hello @Lady Fitzgerald,

My apologies for the longer delay, i hope this matter is still of interest to you…

Here goes:

The method Writer_Save_New() is the one to be connected to a Keyboard Shortcut, a Button Command, and/or a Menu item Command, so that it can be invoked whenever you want to save a new Writer document. If it is a New document, then the above procedure is performed; if it is not a New document, then the normal save procedure is performed.

A note about the dialog:

The “Save Dialog” implementation presented below in the function FileSaveDialog_Simple() has fewer features than the dialog that pops up when you choose “Save As...” in LibreOffice. For example it lacks the features of setting a Password, saving the current Selection Only, Editing Filter Options, etc.

However for the purpose of this question, it will suffice.

Steps to perform:

EDIT 1 ( 2018-01-25 )

  • updated the method Writer_SaveNew()

  • added stepwise instructions A) and B)

A) How to Copy-paste a Basic macro into your [My Macros & Dialogs].Standard Basic Library:

  1. Select all text in the code section below, and copy it to the Clipboard by pressing CTRL+C;
  2. In Writer, select the menu Tools : Macros : Edit Macros;
  3. In the Macro IDE Window that appears, in the “Object Catalog” on the left, doubleclick on the item called My Macros & Dialogs so that it expands;
  4. In the expanded section under “My Macros & Dialogs”, doubleclick on the item called Standard so that it expands;
  5. In the expanded section under “Standard”, doubleclick on any item so that it expands ( for example on the item called Module1 ); At the right side of the Macro IDE Window there should now appear all the text contents of the selected Module;
  6. Scroll down to the end of the Module, insert a few empty lines at the end by pressing the ENTER key, then paste all the copied text from the Clipboard by pressing CTRL+V.
  7. Save the Module by pressing CTRL+S.

B) How to Connect a macro to a Keyboard Shortcut:

  1. In Writer, select the menu Tools : Customize...;
  2. In the dialog that appears, select the tab Keyboard;
  3. In the “Shortcut Keys” listbox, scroll down to the Shortcut Key that you would like to use ( in this case i would recommend Shift+Ctrl+Alt+S ), and select it;
  4. In the “Category” listbox, scroll down to the item called LibreOffice Macros, and doubleclick on it so that it expands;
  5. In the expanded section under “LibreOffice Macros”, doubleclick on the item called My Macros so that it expands;
  6. In the expanded section under “My Macros”, doubleclick on the item called Standard so that it expands;
  7. In the expanded section under “Standard”, doubleclick on the Module that contains the methods added in step A), e.g. Module1;
  8. In the “Function” listbox, scroll down to the item called Writer_SaveNew(), and select it;
  9. Click the Modify button;
  10. Click the OK button.

Code:

Sub Writer_SaveNew()
REM See: https://ask.libreoffice.org/en/question/128570/capturing-title-in-writer-document-saved-filename/
REM ...
(more)
edit flag offensive delete link more

Comments

I'm sorry but I still have no idea what is being talked about. Where and what is this Standard Basic Library? Step #2 was gibberish to me.

I need simple, detailed, step by step instructions. Don't assume I know anything.

Lady Fitzgerald gravatar imageLady Fitzgerald ( 2018-01-23 17:06:19 +0100 )edit

Though the questions “How to copy-paste a macro into my Basic Macro Library?” and “How to connect a Shortcut Key to a macro?” might already have been answered in a better way elsewhere on the AskLibreOffice forum, i have included a stepwise instruction for both these tasks in my Original Answer ( under EDIT 1 ).

librebel gravatar imagelibrebel ( 2018-01-25 08:41:17 +0100 )edit

Hi, librebel. I get an error when I use you macro. It says: "BASIC runtime error. Sub-procedure or function procedure not defined," then the code "strDefaultName = Writer_getSentence( 1, oDoc )" is highlighted. Did I do something wrong?

Also would it be possible, using your macro, to get the title from an input field?

Thank you.

Ibelin123 gravatar imageIbelin123 ( 2019-01-13 04:24:34 +0100 )edit
0

answered 2017-09-04 17:35:56 +0100

Lupp gravatar image

updated 2017-09-04 17:42:17 +0100

https://forum.openoffice.org/en/forum...
This should be at least a starting point for you. You may search for your interpunktion instead of taking a whole line of text. (The original code may also wrongly take an empty line if terminated with a hard line break while the paragraph continues.)

edit flag offensive delete link more

Comments

Thanks but, when I read that, my eyes glazed over, then crossed, and my toes curled. That was as solidly over my head as my roof.

Lady Fitzgerald gravatar imageLady Fitzgerald ( 2017-09-04 22:03:29 +0100 )edit

Hello @Lady Fitzgerald,

i think a better solution would be a macro that actually invokes the FilePicker dialog with your custom string as the Default File Name.

i'll be working on such a macro in the coming time, please hold on.

You could then connect this macro to a newly created custom Menu item called "Save New ...", and attach a suitable keyboard shortcut such as CTRL+SHIFT+S to it.

librebel gravatar imagelibrebel ( 2017-09-13 05:32:38 +0100 )edit

Question Tools

3 followers

Stats

Asked: 2017-09-04 17:20:45 +0100

Seen: 1,028 times

Last updated: Jan 25 '18