ristoi General User


Joined: 25 Aug 2009 Posts: 24 Location: Järvenpää
|
Posted: Tue Nov 30, 2010 12:38 pm Post subject: A function for Calc to show the name of a month for number |
|
|
Here follows a Basic macro function NameMNr which can be used also as Calc function for listing month names. It works with one argument which take number 1 ... 12 for the month January ... December along with locale setting. So with Finnish locale setting it gives tammikuu ... helmikuu. With other small numbers there is no error message but 0 is January and - 1 is December so there is two Januarys if a series of numbers is used as arguments over zero value. There is no need for language packages for using different languages for month names but multiple foreign names of months can stay at spreadsheet only by Paste Special.
With no argument result is the name of the first month i.e. January with English locale.
Calc Halp page with header "User-Defined Functions" tells how to install this macro.
| Code: |
Function NameMNr (optional iKuuNro as Integer) as String
REM funktio palauttaa kuukauden nimen kuukausinumerosta
REM 1 = tammikuu (lokalisoituna)... 12 = joulukuu
REM 0 (tai jos argumentti puuttuu) = tammikuu, -1 = joulukuu
REM Ohjelmointi: RJ, avoin ja vapaa koodi
Dim lPvmnro as Long 'sisäinen päivämääränumero
Dim oFunktio as Object 'yleinen Funktio-objekti
Dim argumenttiluettelo As Variant 'Sisältää Calc-funktion argumentit
Dim iKKnro as Integer 'argumentti tarkistettuna
If Ismissing(iKuuNro) or iKuuNro = 0 then
iKKnro = 1
else
iKKnro = (iKuuNro) Mod 12
EndIf
If iKKnro = 0 then
If iKuuNro > 0 then
iKKnro = 12
else
iKKnro = 1
EndIf
EndIf
IF iKKnro < 0 then iKKnro = iKKnro + 13
lPvmnro = Dateserial(2006,iKKnro,1)
argumenttiluettelo=array(lPvmnro, "mmmm")
oFunktio = createUnoService("com.sun.star.sheet.FunctionAccess")
NameMNr = oFunktio.callFunction("TEXT",argumenttiluettelo)
End Function 'NameMNr
|
|
|