Calling Function in Add-in

  • Thread starter Thread starter MikeH2
  • Start date Start date
M

MikeH2

In a VBA Sub, I issue this command:

Dim IsItOpen As Variant
IsItOpen = Application.Run("personal.xla!IsOpenWB", "chart of accounts.xlsx")

And the function in personal.xla is:
Public Function isopenwb(ByVal WBname As String) As Boolean
'returns true if workbook is open
Dim objWorkbook As Object
On Error Resume Next
isopenwb = False
Set objWorkbook = Workbooks(WBname)
If Err = 0 Then isopenwb = True
End Function

But I get an error, "The Macro 'personal.xla!IsOpenWB' cannot be found.
Ideas?
 
It sounds like personal.xla isn't open.

Or maybe IsOpenWB isn't in a general module.
 
That's not enough information.

Is the code in the ThisWorkbook module? Or behind a worksheet?

Select your project in the project explorer in the VBE and click on
Insert|Module.

Then move (not copy) your code there.
 
It is in a module by itself now. It never was part of the Microsoft Excel
Objects. It was always a module. Now it is in Module1 (as I usually rename
modules). But I believe I have other copies of that function elsewhere so I
renamed it to IsOpenWBXX and called it thusly and it works. So I believe it
must be a 'matter of mistaken identity' of my function. Anyway, issue
resolved short-term and I will fix long-term by cleaning up my code and
eliminated dup functions with the same name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top