title: I'm trying to include the Excel MDuration function into VBA code in an Access Module. Is this possible?
body: <p>I'm trying to include the Excel MDuration function into VBA code in an Access Module. Is this possible?</p>
  
  <p>My goal is to calculate the Modified Duration of a bond using the key inputs and have the duration calculation sent to a table. </p>
  
  <p>The code works up until the line "Duration = "=MDURATION(SettlementDate,MaturityDate,Coupon,Yield,Frequency)"</p>
  
  <p>Where I'm I going wrong or is this simply not possible?</p>
  
  <p>My code is as follows.</p>
  
  <pre><code>Public Function CalcDuration()
  
  Dim SettlementDate As Date
  Dim MaturityDate As Date
  Dim Coupon As Double
  Dim Yield As Double
  Dim Duration As Double
  Dim Frequency As Double
  
  
  SettlementDate = InputBox("Enter Settlement Date ", "Enter Value")
  MaturityDate = InputBox("Enter Maturity Date ", "Enter Value")
  Coupon = InputBox("Enter Coupon ", "Enter Value")
  Yield = InputBox("Enter Yield ", "Enter Value")
  Frequency = InputBox("Enter Frequency ", "Enter Value")
  Duration = "=MDURATION(SettlementDate,MaturityDate,Coupon,Yield,Frequency)"
  
  
  CurrentDb.Execute "INSERT INTO Duration" _
      &amp; "(SettlementDate, Duration) VALUES " _
      &amp; "(#" &amp; SettlementDate &amp; "#, " &amp; Duration &amp; ")"
  
  
  
  End Function
  </code></pre>