LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Calling Add-in functions from VBA

Experts,

I have one specific and one general question about add-ins.

System: NT4/XL97
Files: Swift accord matrix.xls
gbcmcrolib.xla
otcmcrolib.xla

I use an add-in (otcmcrolib.xla) to highlight rows in a worksheet
which meet certain criteria. The criteria are stored in an XLS file
(Swift accord matrix.xls). This XLS file has the following code in
the Workbook_BeforeClose event:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim rngLastCell As Range
Dim iRowNumber As Integer
Dim wksMessageTimings As Worksheet

Set wksMessageTimings = Workbooks("Swift accord
matrix.xls").Worksheets("Sheet1")
'Locate the last cell in the sheet.
Set rngLastCell = rngOp01_IdentifyLastCell(wksMessageTimings)

'Get the row number from this.
iRowNumber = rngLastCell.Row

'Add the range as a name.
ThisWorkbook.Names.Add Name:="MessageTimings", _
RefersToR1C1:=Range(Cells(3, 4), Cells(iRowNumber, 8))
End Sub

rngOp01_IdentifyLastCell is an add-in function which accepts a
worksheet object and returns a range object (the add-in gbcmcrolib.xla
is included in the references of the project).

otcmcrolib.xla contains the following code in a code module:

Dim wbk as Workbook
Set wbk = Workbooks.Open("[path]\Swift accord matrix.xls")

Code which uses one of the names in Swift accord matrix.xls in a
VLOOKUP

wbk.Close

When executing the line of code

Set rngLastCell = rngOp01_IdentifyLastCell(wksMessageTimings)

in the Workbook_BeforeClose() event above I get the following error:

Run time error '91';
Object variable or with block variable not set

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

Public Function rngOp01_IdentifyLastCell(ws As Worksheet)
Dim lLastRow As Long
Dim iLastCol As Integer

'Error-handling in case no data in the worksheet. _
Needs to be enhanced.
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

can't operate on it.

All this code works fine when I open and close the XLS file directly.
It is just when it is opened and closed via the add-in
(otcmcrolib.xla) in the manner described above that it doesn't work.

Can anyone give me any insight?

General add-in question:
Is there a good source of information about add-ins which goes beyond
the introductory 'all you have to do is SaveAs .xla and your Workbook
becomes an add-in and users can't see your data and won't be prompted
for saving' etc etc because I have come across more than a few
infuriating little things like my problem described above and presume
there is a great deal I am missing on the subject?

Thanks everyone,

Mark
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling an Add-In BillCPA Excel Discussion (Misc queries) 2 August 11th 05 09:32 PM
Calling certain functions within VBA Myrna Larson[_2_] Excel Programming 0 August 11th 03 10:57 PM
Calling certain functions within VBA Ron de Bruin Excel Programming 0 August 11th 03 10:32 PM
Calling certain functions within VBA james Excel Programming 0 August 11th 03 10:27 PM
Calling VBA functions from a xll Kim[_8_] Excel Programming 2 August 3rd 03 11:48 AM


All times are GMT +1. The time now is 07:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"