OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[Writer] Save with first line as file name.

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Tue Jun 23, 2009 7:02 am    Post subject: [Writer] Save with first line as file name. Reply with quote

As indicated, this macro will save a Writer file using the first line of text in the file as the file name.
Code:
Sub FirstLineFileName_Writer
On Error goto EH
oDoc = ThisComponent
oVC = oDoc.CurrentController.getViewCursor
Mark = oDoc.Text.CreateTextCursorByRange(oVC)'mark position of view cursor.
oTC = oDoc.Text.CreateTextCursor 'created at the beginning of doc.
While oTC.isEndOfParagraph 'skip empty paragraphs.
 oTC.gotoNextParagraph(false)
Wend
oVC.gotoRange(oTC,false) 'a text cursor can't go to the end of a line
oVC.gotoEndOfLine(true)  'so we have to use the view cursor.
filename = oVC.String
oVC.gotoRange(Mark,false) 'return view cursor to original position.
url = ConvertToURL("C:\SomeDirectory\" & filename)'INSERT YOUR DESIRED DIRECTORY PATH.
oDoc.StoreAsURL(url,Array())
End
EH:
MsgBox "You may have illegal file name characters in the first line." & Chr(13)_
& Chr(13) & filename,,"AN ERROR OCCURRED"
End Sub


Last edited by JohnV on Mon Oct 05, 2009 2:56 pm; edited 1 time in total
Back to top
View user's profile Send private message
Tommy27
OOo Advocate
OOo Advocate


Joined: 18 Nov 2006
Posts: 302

PostPosted: Thu Jul 02, 2009 1:43 am    Post subject: Reply with quote

could be useful.
thanks 4 sharin' it
Back to top
View user's profile Send private message
pir
OOo Advocate
OOo Advocate


Joined: 20 May 2009
Posts: 200
Location: France

PostPosted: Thu Jul 02, 2009 2:19 am    Post subject: Reply with quote

this is relevant to my interests too, thanks
_________________
OpenOffice.org, teh best firewall
Back to top
View user's profile Send private message
edovie
General User
General User


Joined: 06 Jul 2009
Posts: 28
Location: Brooklyn [NYC], New York

PostPosted: Sun Jul 12, 2009 11:36 am    Post subject: Reply with quote

Er, how do I use it? I'm not code-savvy. But it's a feature I'd love. How to do?
_________________
~David Eisner~

Windows XP
Mozilla Firefox 3.5.4
OpenOffice.org 3.1.1
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Sun Jul 12, 2009 8:20 pm    Post subject: Reply with quote

Quote:
Er, how do I use it? I'm not code-savvy. But it's a feature I'd love. How to do?

Hopefully this will answer your question.
http://www.oooforum.org/forum/viewtopic.phtml?t=7995
Back to top
View user's profile Send private message
edovie
General User
General User


Joined: 06 Jul 2009
Posts: 28
Location: Brooklyn [NYC], New York

PostPosted: Mon Jul 13, 2009 3:47 pm    Post subject: Reply with quote

Hi John.

I did according to the other thread an apparently it worked. However, I can't find the documents!
_________________
~David Eisner~

Windows XP
Mozilla Firefox 3.5.4
OpenOffice.org 3.1.1
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Tue Jul 14, 2009 5:56 am    Post subject: Reply with quote

Quote:
I did according to the other thread an apparently it worked. However, I can't find the documents!
What documents?
Back to top
View user's profile Send private message
edovie
General User
General User


Joined: 06 Jul 2009
Posts: 28
Location: Brooklyn [NYC], New York

PostPosted: Tue Jul 14, 2009 2:45 pm    Post subject: Reply with quote

JohnV wrote:
Quote:
I did according to the other thread an apparently it worked. However, I can't find the documents!
What documents?


Some random documents of no meaning. But they're not in My Documents or Desktop.
_________________
~David Eisner~

Windows XP
Mozilla Firefox 3.5.4
OpenOffice.org 3.1.1
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
uros
Super User
Super User


Joined: 22 May 2003
Posts: 601
Location: Slovenia

PostPosted: Wed Jul 15, 2009 1:55 am    Post subject: Reply with quote

edovie wrote:
But they're not in My Documents or Desktop.

This program originaly saves your file to the root of disk C:
Code:
url = ConvertToURL("C:\" & filename)'Insert Your Desired Directory Path.

Follow the instruction in a code an insert your path...
For instance
Code:
url = ConvertToURL("C:\user\My documents\Reports\" & filename)

Uros
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group