Save as Fields

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
cargo_02
Posts: 1
Joined: Mon Sep 12, 2011 3:42 pm

Save as Fields

Post by cargo_02 »

Hi,
I have been using this modified code of JohnV with success. The macro is design to automaticaly save the file as a Field called Name in Writer. As I don't understand coding, I seek some help to modify it. I see 2 problems with the macro:
1- I would like to add the date of the day (Insert-Field-Date) after Name in the file name. It would be something like "Marine 2011-09-12.odt".
2- The macro doesn't seem to allow me to use other fields in my document (fields which would not appear in the file name). If I had other fields in my documents (like page number), the macro doesn't work at all.

I would appreciate your help !

Here is the code:

Code: Select all

Sub SaveWithFieldNames
On error goto EH
oDoc = ThisComponent
oTFS = oDoc.getTextFields
enum = oTFS.createEnumeration
While enum.hasMoreElements
oTF = enum.nextElement
Select Case oTF.Content
Case "Name" : N = oTF.Anchor.String 
End Select 
Wend
U = "_"
aray = Split(D,"/") 'convert slashes to dashes. 
D = Join(aray,"-")
filename = N & ".odt" 
url = ConvertToURL("/Users/cargo_02/Documents/" & filename) 'Insert Your Desired Directory Path.
oDoc.StoreAsURL(url,Array())
oDoc.Modified = false 'avoid Save being called if doc closed without further edits.
End 'end normal execution.
EH: 'error handler.
MsgBox "You may have illegal file name character." & Chr(13)_
& Chr(13) & filename,,"AN ERROR OCCURRED"
End Sub

Sub Macro1

End Sub
Thanks !
OpenOffice 3.3.0
MacOS 10.7.1
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Save as Fields

Post by JohnV »

Does this help?

Code: Select all

Sub Main
fn = "Marine " & date 
print fn
aray = Split(fn,"/")
fn = Join(aray,"-")
Print fn
End Sub
Post Reply