MS Access Error when using VB code: Excel.WorksheetFunction.xxxxxx

  • Thread starter Thread starter Rick Brown via AccessMonster.com
  • Start date Start date
R

Rick Brown via AccessMonster.com

I am using the following code to try to use the MS Excel funciton trunc,
but I get the error: (I did make sure I have a reference to the MS Excel
Library)

Object doesn't support this property or method (Error 438)

Any suggestions on how to get this code to work.

Function xltrunc(num As Double) As Single
xltrunc = Excel.WorksheetFunction.trunc(num)
End Function

Thank you
Rick Brown
 
"Rick Brown via AccessMonster.com" <[email protected]>
wrote in message
I am using the following code to try to use the MS Excel funciton
trunc, but I get the error: (I did make sure I have a reference to
the MS Excel Library)

Object doesn't support this property or method (Error 438)

Any suggestions on how to get this code to work.

Function xltrunc(num As Double) As Single
xltrunc = Excel.WorksheetFunction.trunc(num)
End Function

According to this Microsoft KB article:

http://support.microsoft.com/default.aspx?scid=kb;en-us;291309
XL2002: Using a Worksheet Function in a Visual Basic Macro

<quote>
Visual Basic for Applications provides many functions that are
equivalent to the built-in worksheet functions in Microsoft Excel.
However, not all of the built-in worksheet functions will work with the
Application or WorksheetFunction objects. You cannot use a built-in
worksheet function in a macro by calling the function as a method of the
Application object or the WorksheetFunction object if there is an
equivalent function in Visual Basic.

</quote>

It makes sense that Trunc would be one of the ones that isn't available,
because the VBA function Fix() seems to do the same thing.
 
Back
Top