Edit: Split from [Writer] Save with first line as file name |
I am not familiar with macros or codes ( I am a neurosurgeon) but I can try modifying your code if you could give a few suggestion on how to retreive data from fields. Thank you!
Edit: Split from [Writer] Save with first line as file name |
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
Case "Age" : A = oTF.Anchor.String
Case "Hosp" : H = oTF.Anchor.String
Case "Date" : D = oTF.Anchor.String
End Select
Wend
U = "_"
aray = Split(D,"/") 'convert slashes to dashes.
D = Join(aray,"-")
filename = N & U & A & U & H & U & D & ".odt"
url = ConvertToURL("C:\users\cat\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