I'm trying to include the Excel MDuration function into VBA code in an Access Module. Is this possible? -
i'm trying include excel mduration function vba code in access module. possible?
my goal calculate modified duration of bond using key inputs , have duration calculation sent table.
the code works until line "duration = "=mduration(settlementdate,maturitydate,coupon,yield,frequency)"
where i'm going wrong or not possible?
my code follows.
public function calcduration() dim settlementdate date dim maturitydate date dim coupon double dim yield double dim duration double dim frequency 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 duration" _ & "(settlementdate, duration) values " _ & "(#" & settlementdate & "#, " & duration & ")" end function
first, make sure you've selected "microsoft excel 14.0 object library" in tools | references
next, need add few things code: add top lines: dim xl object set xl=createobject("excel.application")
change line follows: duration = xl.mduration(settlementdate, maturitydate, coupon, yield, frequency)
here's quick , dirty code: public function calcduration()
dim xl object set xl = createobject("excel.application") dim settlementdate date dim maturitydate date dim coupon double dim yield double dim duration double dim frequency 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 = xl.mduration(settlementdate, maturitydate, coupon, yield, frequency) currentdb.execute "insert duration" _ & "(settlementdate, duration) values " _ & "(#" & settlementdate & "#, " & duration & ")" end function
Comments
Post a Comment