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