Ask Your Question

I have recorded a "save as" macro but I need the macro to save the date and time in the file name, I keep getting a sintax error. Can anyone help please?

asked 2015-05-14 16:43:44 +0200

Philbowen gravatar image

updated 2015-08-27 11:56:52 +0200

Alex Kemp gravatar image

System used id windows 7 and 8

edit retag flag offensive close merge delete


Of course - you have to correct the syntax-Error ...

Sorry - nobody can really help without reading the grumpy Makrocode

karolus gravatar imagekarolus ( 2015-05-14 21:16:36 +0200 )edit

3 Answers

Sort by » oldest newest most voted

answered 2015-05-15 14:22:04 +0200

Philbowen gravatar image

updated 2015-05-15 14:35:14 +0200

karolus gravatar image

Thanks for pointing out my spelling, it had been a long day. I have copied the coding but I cant get the SYNTAX right, to be able to save each time with a date and time within the file name. Could some one look at the code and work out how to get it to add "NOW" to the file name "PLANT%20CHECKv1.2.4.odt

    dim document   as object
    dim dispatcher as object
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("")

    dim args1(1) as new
    args1(0).Name = "URL"
    args1(0).Value = "file:///P:/Engineering/Plant%20Check%20Results/PLANT%20CHECKv1.2.4.&"NOW"().odt"
    args1(1).Name = "FilterName"
    args1(1).Value = "writer8"

    dispatcher.executeDispatch(document, ".uno:SaveAs", "", 0, args1())

end sub

[edit code for readability Karolus ]

I think the error is the dispatcher.executeDispatch(document, ".uno:SaveAs", "", 0, args1())

Thanks Phil

edit flag offensive delete link more

answered 2015-05-15 14:43:06 +0200

karolus gravatar image

Should work if you change args1(0).value = .... to

args1(0).Value = "file:///P:/Engineering/Plant%20Check%20Results/PLANT%20CHECKv1.2.4." & NOW & "().odt"
edit flag offensive delete link more

answered 2015-05-15 17:32:14 +0200

pierre-yves samyn gravatar image


Warn to the creation of subfolders, if the NOW function returns the date as: 15/05/2015 17:28:47 (my environment is french).

You can avoid it by removing your separator (e.g. / and :) this way:

dim sUrl as string
args1(0).Name = "URL"
sUrl =  "file:///C:/Engineering/Plant%20Check%20Results/PLANT%20CHECKv1.2.4." 
sUrl =  sUrl & join(split(join(split(now, "/"), ""), ":")) & ".odt" 
args1(0).Value = sUrl


edit flag offensive delete link more


@pierre-yves samyn

format(now, "yyyy-mm-dd--hh:mm") 'or simlar'
karolus gravatar imagekarolus ( 2015-05-15 17:50:26 +0200 )edit

Of course... Why complicate life to make it simple when it's so simple to complicate, again... Thank's @karolus :)

pierre-yves samyn gravatar imagepierre-yves samyn ( 2015-05-15 17:53:26 +0200 )edit
Login/Signup to Answer

Question Tools



Asked: 2015-05-14 16:43:44 +0200

Seen: 1,196 times

Last updated: May 15 '15