[Solved] [Writer] Save first line as file name

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
asbaker
Posts: 8
Joined: Sun Nov 08, 2009 7:26 pm

[Solved] [Writer] Save first line as file name

Post by asbaker »

 Edit: Split from [Writer] Save with first line as file name 
This is an old thread but i'm a newbie after using Word 2000/2007 forever. I copied and installed the macro exactly as above and always get the error line about illegal characters in first line. That line is a variation of the words: LIBRE notes. I'd appreciate some hint of what I am doing wrong. I copied it exactly using the line including .odt even though I am using .doc Also tried my own path. Nothing gets past the error. Perhaps Libre Writer 7.1.6.2 is different? Thanks.
Last edited by Hagar Delest on Sat Oct 23, 2021 10:18 am, edited 1 time in total.
Reason: Tagged [Solved].
OpenOffice 3.1 on Windows XP / vista
JeJe
Volunteer
Posts: 2778
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Writer] Save with first line as file name.

Post by JeJe »

Works for me on LO 7... did you remember the "\" at the end of your folder name

("C:\tmp\" & filename & ".odt")

LibreOffice 5.4 is the last to support Windows XP and Windows Vista if you're still using that.

https://ask.libreoffice.org/t/whats-lat ... ines/24434

Edit:

If you comment out the line

Code: Select all

On Error goto EH
with a ' in front so it becomes

Code: Select all

'On Error goto EH
then you can see on which line the error occurs.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
asbaker
Posts: 8
Joined: Sun Nov 08, 2009 7:26 pm

Re: Question about macro: Save first line as file name.

Post by asbaker »

Thank you - that worked. Now I need to find a way to delete all the macros that did not work :)
Have a great day.
OpenOffice 3.1 on Windows XP / vista
JeJe
Volunteer
Posts: 2778
Joined: Wed Mar 09, 2016 2:40 pm

Re: Question about macro: Save first line as file name.

Post by JeJe »

If you want the saveas dialog to pop up with the first line as file name for a new document then it can be done by setting the document title to it first:

Code: Select all


sub SaveDialogWithFirstLineSuggestion
dim document   as object
dim dispatcher as object
txt = thiscomponent.text.createenumeration.nextelement.string
thiscomponent.title = txt
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:SaveAs", "", 0, Array())
end sub

(Edit: I seem to remember this was asked for fairly recently but i can't find the thread and nobody (including me) had the answer.)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Hagar Delest
Moderator
Posts: 32650
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Question about macro: Save first line as file name.

Post by Hagar Delest »

asbaker wrote:Now I need to find a way to delete all the macros that did not work :)
Open the Basic IDE and delete all the sub...end macros that are of no use.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Post Reply