"Cannot Find" Using Analysis ToolPak Visual Basic Function

ID: Q118797

The information in this article applies to:

SYMPTOMS

In Microsoft Excel, if you use one of the functions provided in the Analysis ToolPak-Visual Basic for Applications add-in (ATPVBAEN.XLA), such as the EDATE() function, you receive the following error message:

   Run-time error '1004':

   Cannot find macro '[ATPVBAEN.XLA]REG!reg_EDATE'.

where the name of the function that you use appears in the place of EDATE in the above error message.

CAUSE

This error message appears when you use any of the following Analysis ToolPak functions in a Visual Basic module:

   New Function    Old Function
   ----------------------------

   EDATE           NEWMONTH
   EOMONTH         NEWMONTHE
   CUMIPMT         CUMPI
   TBILLEQ         TBILLYEQ
   TBILLPRICE      TBILLP
   TBILLYIELD      TBILLY

WORKAROUNDS

To avoid receiving this error message when you use one of these functions in a Visual Basic procedure, you can do either of the following:

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support professionals can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

   Sub Test()
      Dim x as Date
      x = Application.ExecuteExcel4Macro("EDATE(datevalue(""1/1/94""),5)")
   End Sub

   NOTE: When you use this method with the EOMONTH() function, the value
   returned is one day less than the correct value. To avoid this
   problem, use the workaround below.

   -or-

  • Use the following custom functions in the place of EOMONTH() and EDATE().

       ' This function returns the serial number date for the last day of the
       ' month that is the indicated number of months before or after
       ' start_date.
    
       Function EO_Month(start_date, months)
          EO_Month = DateSerial(Year(start_date), _
            Month(start_date) + months + 1, 0)
       End Function
    
       'This function returns the serial number date that is the indicated
       'number of months before or after start_date.
    
       Function E_Date(start_date, months)
          Dim DaysInMonth As Integer
          DaysInMonth = Day(DateSerial(Year(start_date), _
            Month(start_date) + months + 1, 1) - 1)
          If Day(start_date) > DaysInMonth Then
             E_Date = DateSerial(Year(start_date), _
                Month(start_date) + months, DaysInMonth)
          Else
             E_Date = DateSerial(Year(start_date), _
                Month(start_date) + months, Day(start_date))
          End If
       End Function
    
       ' Example procedure using EO_Month function
       Sub Test1()
          Dim x As Date
          x = EO_Month(start_date:="1/1/94", months:="5")
          MsgBox x
       End Sub
    
       ' Example procedure using E_Date function
       Sub Test2()
          Dim x as Date
          x = E_Date(start_date:="1/1/94", months:="5")
          MsgBox x
       End Sub
    
    

    STATUS

    Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. This problem was corrected in Microsoft Excel for Windows version 5.0c.

    Note that in Microsoft Excel version 5.0c, you only receive this error message when you use a function in ATPVBAEN.XLA if the file is not open when you run the procedure that contains the function.

    MORE INFORMATION

    To view the Visual Basic functions that are included in the Analysis ToolPak-Visual Basic for Applications add-in, do the following:

    1. Open the file ATPVBAEN.XLA (located in the LIBRARY\ANALYSIS

       subdirectory of the Microsoft Excel directory).
    
    
    2. In a Visual Basic module, choose Object Browser from the View menu.

    3. From the Libraries/Workbooks list, select ATPVBAEN.XLA.

    The Methods/Properties list contains all of the Visual Basic functions included in the Analysis ToolPak - Visual Basic for Applications add-in.

    Additional query words: 5.00 atp addins err msg

    Keywords          : xlwin kbfixlist
    Version           : 5.00
    Platform          : WINDOWS

    Last Reviewed: June 1, 1999