AddIn functions in code?

R

Rbp9ad

Can I use functions from addIns in VBA code? I have custom functions as well
as some from Excel's addIns that I would like to use in a module. Is this
possible? (Also I am new to programming and I am trying to learn VBA from
the few examples in John Walkenbach's Excel 2003 Bible. Would his Excel VBA
book be a good start?)
 
D

Dave Peterson

One way is to add a reference to that addin to your workbook's project.

Make sure that the project name isn't VBAProject--make it a nice unique name.
Select your addin's project in the VBE, hit F4 to see the properties window and
change the (name) property.

Then select your workbook's project that will use that addin and
tools|references
and check that addin's project.

Then you can use your functions just like they're built into VBA.

You could also use something like:

dim res as variant
res = Application.Run("youraddinname.xla!yourfunction", parm1, parm2, parm3)

With no references.
 
G

Guest

Yes it's a great book.

yes you can use functions in code
help>Worksheetfunction. see list of supported functions and note that
WorksheetFunction.functionname(stuffhere) is the typical syntax

Syntax is the hardest component of coding.
 
R

Rbp9ad

I wrote the function to return a vendor number from an account number.

Option Explicit
Function Vendor(VR As Variant) As String

Application.Volatile True


Dim Acct As Variant


Acct = Strings.Left(RRLookup(VR, 11), 12)

Select Case Acct
Case Is = "236SPDTI DTI", "207SPDI3 DI3", "207SPDTI DTI"
Vendor = "36359"
Case Is = "202SPDTI DTI"
Vendor = "2810"
Case Is = "240SPLIG LIG"
Vendor = "2814"
Case Else
Vendor = ""
End Select
End Function
The account number is looked up from a spreadsheet that is entered manually.
I was wondering if there was a way to make the function less sensitive to
typos and differing input (Additional spaces etc.).
 

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

Top