[Solved] Accessing File > Properties > User Defined fields

Creating a macro - Writing a Script - Using the API

[Solved] Accessing File > Properties > User Defined fields

Postby Lazy-legs » Fri Jan 25, 2008 8:31 pm

Hello,

It's rather easy to retrieve document properties stored in File -> Properties -> General. For example, using the following code, you can retrieve the current document's title:

Code: Select all   Expand viewCollapse view
ThisDoc=ThisComponent
DocName=ThisDoc.DocumentInfo.Title


I wonder whether it's possible to access the use-defined fields under the User Defined tab in a similar manner? For example, I'd like to rename the Info 1 field to Status, so I can retrieve the document's status via a macro. Is this doable?

Thank you!

Kind regards,
Dmitri
Last edited by Hagar Delest on Tue Jun 10, 2008 2:02 pm, edited 3 times in total.
Reason: tagged the thread as Solved.
User avatar
Lazy-legs
 
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin

Re: Accessing Use Defined fields

Postby JohnV » Fri Jan 25, 2008 11:11 pm

The first macro will change the Info 1 field found at File > Properties > User Defined tab to Status but why bother. The second macro will read the content of that field no matter what its name is.
Code: Select all   Expand viewCollapse view
Sub Main
ThisDoc=ThisComponent
ThisDoc.DocumentInfo.setUserFieldName(0,"Status")
End Sub

Sub GetInfo1
MsgBox ThisComponent.DocumentInfo.getUserFieldValue(0)
End Sub
JohnV
Volunteer
 
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Accessing Use Defined fields

Postby Lazy-legs » Fri Jan 25, 2008 11:56 pm

Thank you very much, JohnV!

Kind regards,
Dmitri
User avatar
Lazy-legs
 
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin

Re: [Solved] Accessing Use Defined fields

Postby JohnV » Sat Jan 26, 2008 8:53 am

I would suggest that you or a moderator change the Subject of your original post to:
[Solved] Accessing File > Properties > User Defined fields
JohnV
Volunteer
 
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: [Solved] Accessing File > Properties > User Defined fields

Postby Hagar Delest » Sat Jan 26, 2008 9:02 am

Done.
AOO 4.1.6 on Xubuntu 18.10 and 4.1.5 on Windows 7 (with winPenPack port).
User avatar
Hagar Delest
Moderator
 
Posts: 28390
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: [Solved] Accessing File > Properties > User Defined fields

Postby Lazy-legs » Sat Jan 26, 2008 11:43 am

Sorry, I should have done this myself. I'll try to remember this next time.

Kind regards,
Dmitri
User avatar
Lazy-legs
 
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin

Re: [Solved] Accessing File > Properties > User Defined fields

Postby JohnV » Sat Jan 26, 2008 10:01 pm

Thinking about the viewing macro today I realized we can either view or edit it all in one macro. So let's kill two birds with one stone.
Code: Select all   Expand viewCollapse view
Sub ViewOrEditInfo_1
Dim s,a,n : s = ThisComponent.DocumentInfo.getUserFieldValue(0)
a = "You can edit the current text in the Info 1 field below." & Chr(13)
a = a & Chr(13) & "'OK' accepts edited text, 'Cancel' leaves it alone."
n = InputBox(a,,s)
If n = "" then End
ThisComponent.DocumentInfo.setUserFieldValue(0,n)
End Sub
JohnV
Volunteer
 
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 3 guests