0
   

Call VBA DLL Function from Excel

 
 
hcdusty
 
Reply Tue 22 Jul, 2014 09:36 am
Hi
We have been able to call and execute a DLL from VBA and stuff the results back to a cell in a worksheet. We'd now like to call that same function from the excel worksheet, pass the arguments to it and have it populate the calling cell just as any other Excel function (e.g. SUM).

When we call it, however, we get a #NAME?
Can't seem to crack this one.

Here is our VBA code. It works without a hitch within the VBAProject.


Option Explicit
Option Base 1
Declare Function PressureFallTime Lib _
"C:\Excel Unit Test Builder\Measurement Functions.dll" _
(ByVal inspPressure As Double, ByVal setPEEP As Double, ByRef y As Double, ByVal dt As Double, _
ByVal t0 As Double, ByVal expectedHighLimit As Double, cursorIndices As Double, passFail As Integer, _
resultOut As Double, ByVal yArraySize As Long, ByVal ciAarraySize As Long) As Long

'int32_t PressureFallTime(double inspPressure, double setPEEP, double *y, double dt, double t0, double expectedHighLimit, double *cursorIndices, int16_t *passFail,
'double *resultOut, int32_t len, int32_t len2);

Sub Falltime()

'=================================================================================
' Declare varibles here
'=================================================================================
Dim pres_array_size As Integer ' Constant: Holds pressure array size from the worksheet
Dim inspPressure As Double ' Placeholder variable for Input or Output values
Dim passFail As Integer ' Output: Holds Pass/Fail Result
Dim result As Double ' Output: Holds measured PEEP Value
Dim y() As Double ' Input: Array that holds all baseline pressure values
Dim setPEEP As Double ' Input: Holds PEEP high limit
Dim expectedHighLimit As Double ' Input: Holds PEEP low limit
Dim referenceTriggerIndex As Double ' Input: Holds start point for PEEP measurement
Dim dt As Double ' Input: Holds sample rate of pressure data
Dim t0 As Double ' Input: Holds value where pressure waveform begins
Dim cursorIndices(2) As Double ' Output: Holds cursor placement data
Dim yArraySize As Long ' DLL Field: Holds Array Size info
Dim ciAarraySize As Long ' DLL Field: Holds Cursor Array info
Dim Pass_Fail As String ' Used to convert passFail integer into "Pass" or "Fail" string
Dim iterate As Integer

'=================================================================================
' Load the variables from the worksheet here
'=================================================================================

pres_array_size = Worksheets("waveform data").Cells(11, 7).Value
'expectedLowLimit = Worksheets("waveform data").Cells(7, 9).Value
expectedHighLimit = Worksheets("waveform data").Cells(7, 10).Value
referenceTriggerIndex = Worksheets("waveform data").Cells(3, 6).Value
dt = Worksheets("waveform data").Cells(11, 5).Value
t0 = Worksheets("waveform data").Cells(3, 6).Value
yArraySize = Worksheets("waveform data").Cells(11, 7).Value
ciAarraySize = 2
ReDim y(pres_array_size)

'=================================================================================
' Load the y baseline pressure array from the worksheet here
'=================================================================================

For iterate = 2 To (pres_array_size - 1)

y(iterate) = Worksheets("waveform data").Cells(iterate, 2).Value

Next

'=================================================================================
' Call and process the DLL here
'=================================================================================

Call PressureFallTime(inspPressure, setPEEP, y(1), dt, t0, expectedHighLimit, cursorIndices(1), passFail, result, yArraySize, ciAarraySize)
If passFail = 0 Then Pass_Fail = "Fail"
If passFail = 1 Then Pass_Fail = "Pass"

'(ByVal inspPressure As Double, ByVal setPEEP As Double, ByRef y As Double, ByVal dt As Double, _
ByVal t0 As Double, ByVal expectedHighLimit As Double, cursorIndices As Double, passFail As Integer, _
resultOut As Double, ByVal yArraySize As Long, ByVal ciAarraySize As Long)

'=================================================================================
' Display the results on the spreadsheet here
'=================================================================================

Worksheets("waveform data").Cells(10, 19).Value = result
Worksheets("waveform data").Cells(11, 19).Value = Pass_Fail



End Sub
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 2,177 • Replies: 1
No top replies

 
jespah
 
  2  
Reply Tue 22 Jul, 2014 11:55 am
@hcdusty,
Maybe your Excel formula isn't working. The reason I suggest that is because that's the kind of error that Excel throws. So maybe try VB code with a formula that you know works, something really simple like =A1
0 Replies
 
 

 
  1. Forums
  2. » Call VBA DLL Function from Excel
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 04/26/2024 at 06:43:39