View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Mark[_21_] Mark[_21_] is offline
external usenet poster
 
Posts: 3
Default Calling Add-in functions from VBA

Ronald,

Thanks for your response. I have tried what you suggested but still
haven't succeeded. Indeed as I have expanded the toolset I have
encountered other errors along the same lines.

I think I have a fundamental mis-understanding of passing data between
projects. I can pass primitive types between projects no problem, it
just breaks down (or only works inconsistently) when I try to pass
objects. As in the example below:

Public Function rngOp01_IdentifyLastCell(ws As Worksheet) As Range
Dim lLastRow As Long
Dim iLastCol As Integer
On Error Resume Next

With ws

'Find the last real row
lLastRow = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row

'Find the last real column
iLastCol = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column
End With

'Return statement
Set rngOp01_IdentifyLastCell = ws.Cells(lLastRow, iLastCol)
End Function


When as I said in my first post
When I step through the code, it seems like the Worksheet gets passed
to rngOp01_IdentifyLastCell (ie ws.Application.ActiveCell.Value is the
value in Sheet1!A1 of Swift accord matrix.xls) only the code
can't operate on it (ie iLastCol and lLastRow don't get set).


And more recently when I call another function
(calFunc01_GetDailyReportDate)which accepts a date and returns a date,
the date gets passed and the function works on it but it is not
returned. In desparation I have changed this function to have it
return an integer which it does no problem so I suppose I could write
a date converter but I don't want to. I want my function library
(read Add-in) to work.

So, my questions:
Which if any of these is the format of a function return statement?
function_name() = result
function_name = result
Set function_name() = result
Set function_name = result

Often when I add a reference to the add-in (gbcmcrolib.xla) to a
project I get the "Bad NT Image" message. Could this be the cause of
my inability to pass objects?

Anything of interest about passing objects between projects?

What I'm going to do:
I am going to take the code from my project, make another add-in with
it, reference it in the same project and see if this can pass objects.

Thanks everyone,

Mark