Using Calc Functions in Macros

In addition to the native BASIC functions, you can call Calc functions in your macros and scripts and set Calc functions in cell formulas.

Kalde interne Calc-funktioner i Basic

Brug funktionen CreateUNOService til at tilgÄ tjenestencom.sun.star.sheet.FunctionAccess.

Eksempel:

The example below creates a function named MyVlook that calls the VLOOKUP Calc function over a data array passed as argument and returns the value found by the function.


    Function MyVlook(Lookup, DataArray As Object, Index As Integer, SortedRangeLookup as Byte)
        Dim oService As Object
        Set oService = createUnoService("com.sun.star.sheet.FunctionAccess")
        ' Always use the function name in English
        MyVlook = oService.callFunction("VLOOKUP", Array(Lookup, DataArray, Index, SortedRangeLookup))
    End Function
  

The macro below presents an example of how the MyVlook function can be called. If first creates a 5-by-2 data array and then calls the function MyVlook and shows the returned value using MsgBox.


    Sub CallingMyVlook()
        ' Creates a 5 by 2 array and fills it with data
        Dim myData(1 to 5, 1 to 2) as Variant
        myData(1, 1) = 1 : myData(1, 2) = "Strongly disagree"
        myData(2, 1) = 3 : myData(2, 2) = "Disagree"
        myData(3, 1) = 5 : myData(3, 2) = "Undecided"
        myData(4, 1) = 7 : myData(4, 2) = "Agree"
        myData(5, 1) = 9 : myData(5, 2) = "Strongly agree"
        ' Looks up the data array
        Dim result as String
        result = MyVlook(4, myData, 2, 1)
        ' Shows the message "Disagree"
        MsgBox result
    End Sub
  

Setting Cell Formulas Containing Internal Calc Functions

Use the formula text string to add a formula to a spreadsheet cell.

note

All Calc functions must be expressed with their English names.


Eksempel:


Sub AssignFormulaToCell
REM Add a formula to cell A1. Function name must be in English.
    oCell = ThisComponent.Sheets.getByIndex(0).getCellRangeByName("A1")
    oCell.Formula = "=SUM(B1:B10)"
REM Cell A1 displays the localized function name
End Sub

Kald af Calc-tillĂŠgsfunktioner i BASIC

Calcs tillĂŠgsfunktioner findes i tjenesten com.sun.star.sheet.addin.Analysis.

Eksempel:


REM Example calling Add-in function SQRTPI
Funktionen MySQRTPI(arg som dobbelt) som dobbelt
   Dim oService as Object
   oService = createUNOService("com.sun.star.sheet.addin.Analysis")
   MySQRTPI = oService.getSqrtPi(arg)
End Function

Setting Cell Formulas with Add-In Functions

The Add-In function must be expressed by its UNO service name.

Eksempel:


Sub AssignAddInFormulaToCell
REM Add an Add-In formula to cell A1. Function name is the UNO service name.
    oCell = ThisComponent.Sheets.getByIndex(0).getCellRangeByName("A1")
    oCell.Formula = "=com.sun.star.sheet.addin.Analysis.getBin2Dec(B1)"
REM Cell A1 displays the localized function name
End Sub

Add-In Functions UNO service Names

The table below presents a list of all Calc Add-In functions and their respective UNO service names.

Calc Function name

UNO service name

PÅLØBRENTE

com.sun.star.sheet.addin.Analysis.getAccrint

PÅLØBRENTE.UDLØB

com.sun.star.sheet.addin.Analysis.getAccrintm

AMORDEGRC

com.sun.star.sheet.addin.Analysis.getAmordegrc

AMORLINC

com.sun.star.sheet.addin.Analysis.getAmorlinc

BESSELI

com.sun.star.sheet.addin.Analysis.getBesseli

BESSELJ

com.sun.star.sheet.addin.Analysis.getBesselj

BESSELK

com.sun.star.sheet.addin.Analysis.getBesselk

BESSELY

com.sun.star.sheet.addin.Analysis.getBessely

BIN.TIL.DEC

com.sun.star.sheet.addin.Analysis.getBin2Dec

BIN2HEX

com.sun.star.sheet.addin.Analysis.getBin2Hex

BIN.TIL.OKT

com.sun.star.sheet.addin.Analysis.getBin2Oct

COMPLEX

com.sun.star.sheet.addin.Analysis.getComplex

CONVERT

com.sun.star.sheet.addin.Analysis.getConvert

KUPONDAGE.SA

com.sun.star.sheet.addin.Analysis.getCoupdaybs

KUPONDAGE.A

com.sun.star.sheet.addin.Analysis.getCoupdays

KUPONDAGE.ANK

com.sun.star.sheet.addin.Analysis.getCoupdaysnc

KUPONDAG.NÆSTE

com.sun.star.sheet.addin.Analysis.getCoupncd

KUPONBETALINGER

com.sun.star.sheet.addin.Analysis.getCoupnum

KUPONDAG.FORRIGE

com.sun.star.sheet.addin.Analysis.getCouppcd

AKKUM.RENTE

com.sun.star.sheet.addin.Analysis.getCumipmt

AKKUM.HOVEDSTOL

com.sun.star.sheet.addin.Analysis.getCumprinc

DEC.TIL.BIN

com.sun.star.sheet.addin.Analysis.getDec2Bin

DEC.TIL.HEX

com.sun.star.sheet.addin.Analysis.getDec2Hex

DEC.TIL.OKT

com.sun.star.sheet.addin.Analysis.getDec2Oct

DELTAB

com.sun.star.sheet.addin.Analysis.getDelta

DISKONTO

com.sun.star.sheet.addin.Analysis.getDisc

KR.DECIMAL

com.sun.star.sheet.addin.Analysis.getDollarde

KR.BRØK

com.sun.star.sheet.addin.Analysis.getDollarfr

VARIGHED

com.sun.star.sheet.addin.Analysis.getDuration

EDATO

com.sun.star.sheet.addin.Analysis.getEdate

EFFEKTIV.RENTE

com.sun.star.sheet.addin.Analysis.getEffect

SLUT.PÅ.MÅNED

com.sun.star.sheet.addin.Analysis.getEomonth

FEJLFUNK

com.sun.star.sheet.addin.Analysis.getErf

FEJLFUNK.KOMP

com.sun.star.sheet.addin.Analysis.getErfc

DOBBELT.FAKULTET

com.sun.star.sheet.addin.Analysis.getFactdouble

FVTABEL

com.sun.star.sheet.addin.Analysis.getFvschedule

STØRSTE.FÆLLES.DIVISOR

com.sun.star.sheet.addin.Analysis.getGcd

GETRIN

com.sun.star.sheet.addin.Analysis.getGestep

HEX.TIL.BIN

com.sun.star.sheet.addin.Analysis.getHex2Bin

HEX.TIL.DEC

com.sun.star.sheet.addin.Analysis.getHex2Dec

HEX.TIL.OKT

com.sun.star.sheet.addin.Analysis.getHex2Oct

IMAGABS

com.sun.star.sheet.addin.Analysis.getImabs

IMAGINÆRDEL

com.sun.star.sheet.addin.Analysis.getImaginary

IMARGUMENT

com.sun.star.sheet.addin.Analysis.getImargument

IMAGKONJUGERE

com.sun.star.sheet.addin.Analysis.getImconjugate

IMAGCOS

com.sun.star.sheet.addin.Analysis.getImcos

IMAGCOSH

com.sun.star.sheet.addin.Analysis.getImcosh

IMAGCOT

com.sun.star.sheet.addin.Analysis.getImcot

IMAGCSK

com.sun.star.sheet.addin.Analysis.getImcsc

IMAGCSKH

com.sun.star.sheet.addin.Analysis.getImcsch

IMAGDIV

com.sun.star.sheet.addin.Analysis.getImdiv

IMAGEKSP

com.sun.star.sheet.addin.Analysis.getImexp

IMAGLN

com.sun.star.sheet.addin.Analysis.getImln

IMAGLOG10

com.sun.star.sheet.addin.Analysis.getImlog10

IMAGLOG2

com.sun.star.sheet.addin.Analysis.getImlog2

IMAGPOTENS

com.sun.star.sheet.addin.Analysis.getImpower

IMAGPRODUKT

com.sun.star.sheet.addin.Analysis.getImproduct

IMAGREELT

com.sun.star.sheet.addin.Analysis.getImreal

IMAGSEK

com.sun.star.sheet.addin.Analysis.getImsec

IMAGSEKN

com.sun.star.sheet.addin.Analysis.getImsech

IMSIN

com.sun.star.sheet.addin.Analysis.getImsin

IMAGSINH

com.sun.star.sheet.addin.Analysis.getImsinh

IMAGKVROD

com.sun.star.sheet.addin.Analysis.getImsqrt

IMAGSUB

com.sun.star.sheet.addin.Analysis.getImsub

IMAGSUM

com.sun.star.sheet.addin.Analysis.getImsum

IMAGTAN

com.sun.star.sheet.addin.Analysis.getImtan

RENTEFOD

com.sun.star.sheet.addin.Analysis.getIntrate

ER.LIGE

com.sun.star.sheet.addin.Analysis.getIseven

ER.ULIGE

com.sun.star.sheet.addin.Analysis.getIsodd

MINDSTE.FÆLLES.MULTIPLUM

com.sun.star.sheet.addin.Analysis.getLcm

MVARIGHED

com.sun.star.sheet.addin.Analysis.getMduration

MAFRUND

com.sun.star.sheet.addin.Analysis.getMround

MULTINOMIAL

com.sun.star.sheet.addin.Analysis.getMultinomial

ANTAL_ARBEJDSDAGE

com.sun.star.sheet.addin.Analysis.getNetworkdays

NOMINEL

com.sun.star.sheet.addin.Analysis.getNominal

OKT.TIL.BIN

com.sun.star.sheet.addin.Analysis.getOct2Bin

OKT.TIL.DEC

com.sun.star.sheet.addin.Analysis.getOct2Dec

OKT.TIL.HEX

com.sun.star.sheet.addin.Analysis.getOct2Hex

ULIGE.KURS.PÅLYDENDE

com.sun.star.sheet.addin.Analysis.getOddfprice

ULIGE.FØRSTE.AFKAST

com.sun.star.sheet.addin.Analysis.getOddfyield

ULIGE.SIDSTE.KURS

com.sun.star.sheet.addin.Analysis.getOddlprice

ULIGE.SIDSTE.AFKAST

com.sun.star.sheet.addin.Analysis.getOddlyield

KURS

com.sun.star.sheet.addin.Analysis.getPrice

KURS.DISKONTO

com.sun.star.sheet.addin.Analysis.getPricedisc

KURS.UDLØB

com.sun.star.sheet.addin.Analysis.getPricemat

KVOTIENT

com.sun.star.sheet.addin.Analysis.getQuotient

SLUMPMELLEM

com.sun.star.sheet.addin.Analysis.getRandbetween

MODTAGET.VED.UDLØB

com.sun.star.sheet.addin.Analysis.getReceived

SERIESUM

com.sun.star.sheet.addin.Analysis.getSeriessum

KVRODPI

com.sun.star.sheet.addin.Analysis.getSqrtpi

TBILLEQ

com.sun.star.sheet.addin.Analysis.getTbilleq

STATSOBLIGATION.KURS

com.sun.star.sheet.addin.Analysis.getTbillprice

STATSOBLIGATION.AFKAST

com.sun.star.sheet.addin.Analysis.getTbillyield

UGE.NR

com.sun.star.sheet.addin.Analysis.getWeeknum

ARBEJDSDAG

com.sun.star.sheet.addin.Analysis.getWorkday

INTERN.RENTE

com.sun.star.sheet.addin.Analysis.getXirr

NETTO.NUTIDSVÆRDI

com.sun.star.sheet.addin.Analysis.getXnpv

ÅR.BRØK

com.sun.star.sheet.addin.Analysis.getYearfrac

AFKAST

com.sun.star.sheet.addin.Analysis.getYield

AFKAST.DISKONTO

com.sun.star.sheet.addin.Analysis.getYielddisc

AFKAST.UDLØBSDATO

com.sun.star.sheet.addin.Analysis.getYieldmat