wesalius
wesalius

Reputation: 155

Libreoffice calc macro to get current date + 14 days into a cell

I need to get todays date + 14 days string formatted in standard dd.mm.yyyy format into Libre Office calc cell.

I already tried the code below, but I lack the knowledge to cope with "Object variable not set" error.

REM  *****  BASIC  *****

sub Datumplus14
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
Dim cell as object
dim term as date
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
term = today()
cell.String = DateAdd("d", 14, datum)

dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, cell)

end sub

Different ideas on how to get this done instead of macro is welcome as well.

Upvotes: 1

Views: 3922

Answers (2)

A.S.H
A.S.H

Reputation: 29342

Function myFunction() As String
    myFunction = Format(Now()+14, "dd.mm.yyyy")
End Function

Upvotes: 1

subdigit
subdigit

Reputation: 431

Hmm, not sure if this will answer the specifics of what you're actually trying to do, but you can easily get the current date and just +14 to it directly in a cell formula.

Like so:

=NOW()+14

The rest is just applying the required date format to that cell. You can also grab the date from another cell too.

Upvotes: 1

Related Questions