Ask Your Question

macro to open a document & read the first line of text

asked 2015-04-13 11:13:08 +0200

jay Arr gravatar image

I have a need for a macro to open a document (it could be WORD, OO, LO, text or rtf) most importantly NOT to display it in a frame (I have 1000's of documents to process) and read the first line of text.

I've been reading Andrew Pitonyak excellent (if opaque) useful macro information but can't find anything useful.

I'm hoping that I can make use of LO's internals and have ONE macro to process any kind of document.Is that unreasonable?

Any pointers and/or code would be most useful.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2015-04-13 13:40:49 +0200

jay Arr gravatar image

updated 2015-04-13 13:42:33 +0200

This great! Thank you very much it's saved me hours of work. Doing this with VBA on Windows is much more complicated!

I've tested it with LO Version: on my Apple iMac with OS X Yosemite 10.10.2 and it works for:

.docx .doc .odt .txt .rtf documents

it doesn't appear to work for .rtfd or TextEdit documents

Where can I find out more about using


edit flag offensive delete link more


css.beans.PropertyValue itself provides nothing of interest here its only a kind of "pack-box" for the Information of Interest ( the pair "Hidden": True in this case)

karolus gravatar imagekarolus ( 2015-04-13 13:59:47 +0200 )edit

Information on Hidden here

DLP done great work bug AKAIK not on RTFD, that said, if I'm not mistaken it is a bundle, a folder containing a RTF. So you can unzip...

pierre-yves samyn gravatar imagepierre-yves samyn ( 2015-04-13 18:56:58 +0200 )edit

answered 2015-04-13 11:53:16 +0200

pierre-yves samyn gravatar image

Hi - Attached is a sample procedure that meets the strict sense to demand: read the first line (and display). I draw your attention to the fact that it is the first line (not the first sentence or paragraph), and that the program not "loop" to look for the first line containing something.

Sub Main

dim sUrlDoc as string
dim oDoc as object, oCursor as object

dim Prop(0) as new

Prop(0).Name = "Hidden"
Prop(0).Value = true

sUrlDoc = convertToUrl("C:\Tests\a.odt")

oDoc = StarDesktop.loadComponentFromURL(sUrlDoc, "_blank", 0, Prop() )
oCursor = oDoc.CurrentController.viewCursor

msgbox oCursor.string


End Sub
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-04-13 11:13:08 +0200

Seen: 887 times

Last updated: Apr 13 '15