喜大普奔之终于会用C写Excel Function了

今天有狗屎运,居然看到了:https://sites.google.com/site/jrlhost/links/excelcdll

简直是我的救星。基本顺着看下来就能搞定。然后吐槽一句,公司居然是x32的office, I 服了U。目前没有想明白为什么。

代码里面要注意的地方:

Option Explicit

'  This file provides an example of calling a C function in a DLL
'  It was writen on a computer with Windows 7 64-bit and Excel 2010 64-bit and has been tested on a computer with Windows 7 32-bit and Excel 2010 32-bit
'  It is provided as an example only. I make no waranties or guarantees about this file, the associated DLL file, the methods contained within, the steps described here or on my website, or anything else. I am unaware of any problems that could be caused by any of these materials, but as with any other code or computer files you find online, use at your own risk.
'  The entire example is based on the example shown http://www.youtube.com/watch?v=x3WWA8eEX9Q, with the addition of the squareOnWorksheet() function and Private keyword in the Declare statement
'  Author: Jonathan Lhost (jrlhost@utexas.edu) June 17, 2012
'  Declare the function that's in the DLL

Private Declare PtrSafe Function squareForEXL Lib _ '以下这个路径差点让我放弃,一开始就没想过公司office是x32。干得好,又让我虚度光阴片刻钟...
"C:\Users\msong1\Documents\Visual Studio 2010\Projects\SquareDLL\Debug\SquareDLL.dll" (ByRef x As Double) As Double

'  Use function on worksheet
Function squareOnWorksheet(dArg As Double) As Double
   squareOnWorksheet = squareForEXL(dArg)
End Function

'  Example using the function from VBA
Sub useSquareInVBA()
   MsgBox squareForEXL(10)
End Sub

棒棒哒~


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

取啥都被占用

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值