XLL+ Class Library

CXlOper::SetLongFormula

Set the formula of the referenced cell, in local format, for formulae of more than 255 characters

[C++]
BOOL SetLongFormula(
   const CString& strFormula,
   BOOL bArray = FALSE,
   BOOL bA1 = TRUE
) const;

Parameters

strFormula

String buffer containing the formula. Formulae must contain less than 1024 characters.

The formula is assumed to be in the current language (i.e. in "local" form), using punctuation derived from the user's regional settings, and function names derived from the Excel version.

If the formula is not in the correct format for the current settings, then the call will fail. To use a formula which works under all language settings, see CXlOper::SetLongFormulaIntl.

bArray

TRUE if the target should be filled with an array formula; FALSE if each cell should be filled with a standard formula.

bA1

If TRUE, then the formula should contain references in A1 format; if FALSE, the references should be in RC format.

Return value

Returns TRUE if the function was successful, FALSE if it failed. The function can fail if the CXlOper does not contain a reference, if the formula is invalid, or if the function cannot be run in Excel at this time.

Remarks

This function can only be called from macro functions. It will always fail if called from worksheet functions.

It makes use of the COM interface, and is much slower than CXlOper::SetFormula, SetFormula should always be used in preference to SetLongFormula, except for the rare case where a very long formula is unavoidable.

Note also that each of the literal values contained within the string must have 255 characters or less. The entire formula may have up to 1024 characters, but no single argument within it may have more than 255 characters.

International considerations

Be careful when setting formulae that the formula is formatted correctly for the current language settings. For example, arguments in English are separated by commas; in German, semi-colons are used.

You can use CXllApp::GetInternational to get the current list separators and other punctuation characters.

Alternatively, you can use CXlOper::SetFormulaIntl to apply formulae that work in all languages.

Example

CXlOper::SetLongFormula() Example

Requirements

Header: xllplus.h

See Also

CXlOper Class | CXlOper Methods | CXlOper::SetFormula() | CXlOper::SetLongFormulaIntl()