How to call build-in function that is overwritten with same name?

onidarbe

Board Regular
Joined
Mar 22, 2013
Messages
65
Hi,

I'd like to find a way (trick) to exceptionally call a VBA build-in function that is overwritten with a custom function. Excel 2010 64bit

For instance if I want to write my own UBound function with the same name, but in that function be able to call the VBA build-in function UBound.

something like: (not working code!)
Code:
Function UBound(xArray) As Integer
    On Error Resume Next
    If LBound(xArray) <= UBound(xArray) Then   '''array is allocated
         v= callToBuildInUBound(xArray)   '''' ?????
    Else   '''no error in UBound anymore
         v= -1
    End If
    UBound=v
End Function
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Not if you could call the build-in function instead of the one in the module.
Isn't there something in lib "user32" or some other way to skip the user defined function and call upon the VBA build-in one?
 
Upvote 0
Forgive the, potentiall silly, question.
Why does the function need to have the same name as the existing, built in, function?
 
Upvote 0
You can create a UDF with same name, but you lose the build-in one :(
And I would like the same name, just not to forget to use it. It's an update of the build-in one ;)

 
Upvote 0
The compiler shouldn't allow you to create a function called UBound
 
Upvote 0
Hey! you're right! Can't call it UBound, but then why can I create isMissing() ?
Code:
Function isMissing(xThis As Variant) As Boolean '''10/06/2013, michel(dot)be(a)gmail....
'''To replace VBA build-in IsMissing(), because using IsMissing on a copy from an non-allocated array to a non-array-dimentioned variant,
'''will raise a fatal error that closes Excel with the message "Microsoft Excel has stopped working" !!!
    If IsError(xThis) Then
        If CStr(CVErr(xThis)) = "Error 448" Then isMissing = True
    End If
End Function

So I'll keep it calling fUBound :( updated version by now:
Code:
Function fUBound(xArray As Variant, Optional iRank As Integer = 1) As Integer '''14/06/2013, michel(dot)be(a)gmail....'''Same af build-in UBound() but without errors on unallocated arrays
'''I wish I could use the function-name "UBound" and then still be able to call the build-in UBound !?
    If isAllocated(xArray) Then
        fUBound = UBound(xArray, iRank)
    Else
        fUBound = -1
    End If
End Function


Function fLBound(xArray, Optional iRank As Integer = 1) As Integer   '''14/06/2013, michel(dot)be(a)gmail....
'''Same af build-in LBound() but without errors on unallocated arrays
    If isAllocated(xArray) Then
        fLBound = LBound(xArray, iRank)
    Else
        fLBound = 0
    End If
End Function

Function isAllocated(xThis As Variant) As Boolean  '''07/06/2013, michel(dot)be(a)gmail....
    If IsArray(xThis) Then
        On Error Resume Next
        isAllocated = LBound(xThis) <= UBound(xThis)
    End If
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top