macro to access external file and update that file

Hi All

I have had to give up and ask a Question of you all. this is one steep learning curve.

I have a Invoice template which I would like to be able to increase the serial number of by one each time I open it, I did come across a thread that said they did it this by referencing a txt file but then didnt do into any detail of how to do this.

I have got the invoice to work to some degree by having the macro save the invoice as the required file and then clear the data and increase the value by one it then save the file as a ***.ots file as below.

Save_template_URL = ConvertToURL (template_url.string)

if openURL = “” then thisComponent.storeAsUrl(Save_template_URL, array) 'store new template file

the file name is /home/user/my_template.ots

the problem with this is it saves the template file as *.ots and the properties say its a template but when I next open the template it treats is as a spreadsheet file and so disappears when I save the file again

If someone would be kind enough to point me in the right direction, either getting the macro to reference and update a txt or calc file, either that or solve my problem of saving template files I would much appreciate the help.

Linux Mint 18
libre office calc Version:

Best regards Neil