PC Review


Reply
Thread Tools Rate Thread

How to call user defined function (UDF) from custom menu in Excel2003?

 
 
Dutch_Guy
Guest
Posts: n/a
 
      28th Feb 2008
How can I call a user defined function from a custom menu?

I have created an add-in (xla) that contains several functions. These
functions work perfectly and show up under: Insert Function dialog box
under the category: User Defined

I am also able to create a custom menu by following the instructions
on the following awesome site:
http://www.ozgrid.com/VBA/custom-menus.htm

What I am unable to do is to call the functions from the custom menu.

Each UDF has its own module in the xla workbook and starts with Public
Function <function name>(serial As String) As Integer

The OnAction line reads:

..OnAction = "<function name>()"

Error message that I get: The macro '<function name>()' cannot be
found

Can you please help me out what I do wrong and tell me what the
correct syntax for OnAction is?

I appreciate your help.
 
Reply With Quote
 
 
 
 
mcgurkle
Guest
Posts: n/a
 
      28th Feb 2008
On 28 Feb, 13:33, Dutch_Guy <ossen...@gmail.com> wrote:
> How can I call a user defined function from a custom menu?
>
> I have created an add-in (xla) that contains several functions. These
> functions work perfectly and show up under: Insert Function dialog box
> under the category: User Defined
>
> I am also able to create a custom menu by following the instructions
> on the following awesome site:http://www.ozgrid.com/VBA/custom-menus.htm
>
> What I am unable to do is to call the functions from the custom menu.
>
> Each UDF has its own module in the xla workbook and starts with Public
> Function <function name>(serial As String) As Integer
>
> The OnAction line reads:
>
> .OnAction = "<function name>()"
>
> Error message that I get: The macro '<function name>()' cannot be
> found
>
> Can you please help me out what I do wrong and tell me what the
> correct syntax for OnAction is?
>
> I appreciate your help.


Hi Dutch_Guy

I'm not sure why your macros aren't working. Is the custom menu also
created in the add-in? You should probably delete the parentheses from
the string, because these can cause the function to be executed twice.

I'm a bit confused by the part

(serial As String) As Integer

In your custom menu, how can you pass an argument in or use the
result?

If you want to do this, i would recommend that you write an
intermediate function along the lines of:


public sub Intermediate()

dim intTemp as integer

intTemp = OriginalFunctionName("serialstring")

'do something with intTemp

end sub


Then in your menu, call

..OnAction = "Intermediate"

Hope this helps

Laura
 
Reply With Quote
 
RB Smissaert
Guest
Posts: n/a
 
      28th Feb 2008
You need:

..OnAction = "functionname"

So for example:

Function Function1() As String

Then do:

..OnAction = "Function1"


RBS

"Dutch_Guy" <(E-Mail Removed)> wrote in message
news:6363d33f-4a9f-4fca-b890-(E-Mail Removed)...
> How can I call a user defined function from a custom menu?
>
> I have created an add-in (xla) that contains several functions. These
> functions work perfectly and show up under: Insert Function dialog box
> under the category: User Defined
>
> I am also able to create a custom menu by following the instructions
> on the following awesome site:
> http://www.ozgrid.com/VBA/custom-menus.htm
>
> What I am unable to do is to call the functions from the custom menu.
>
> Each UDF has its own module in the xla workbook and starts with Public
> Function <function name>(serial As String) As Integer
>
> The OnAction line reads:
>
> .OnAction = "<function name>()"
>
> Error message that I get: The macro '<function name>()' cannot be
> found
>
> Can you please help me out what I do wrong and tell me what the
> correct syntax for OnAction is?
>
> I appreciate your help.


 
Reply With Quote
 
Dutch_Guy
Guest
Posts: n/a
 
      28th Feb 2008
Laura,

Thank you very much for your reply. You and RBS solved my problem. I
removed the parentheses.
You told me that I confused you and I confused myself as well, I am
still a beginner when it comes to VBA :-)

> (serial As String) As Integer
>
> In your custom menu, how can you pass an argument in or use the
> result?


Because my code line with .OnAction was not working, I did not expect
to get a no arguments error message.
So after you resolved my OnAction problem, I created a public sub
Intermediate() in which an inputbox is asking for a cell selection.
The selected cell contains the serial number (variant data type) which
is passed to the function.

My goal is to create a custom menu with formulas that are very
specifically designed for our company needs which can be used by
department employees. I want to avoid that each employee has to go to
the Insert Function dialog box, select the category: User Defined and
then browse through the large list of functions. With a custom menu, I
can add sub menus (categories) to make the formula selection easier.

I believe now I have to focus on error handling since canceling the
input dialog box or selecting multiple cells gives error messages :-)

Dutch_Guy


On Feb 28, 8:42 am, mcgurkle <Laura.McG...@gmail.com> wrote:
> On 28 Feb, 13:33, Dutch_Guy <ossen...@gmail.com> wrote:
>
>
>
> > How can I call a user defined function from a custom menu?

>
> > I have created an add-in (xla) that contains several functions. These
> > functions work perfectly and show up under: Insert Function dialog box
> > under the category: User Defined

>
> > I am also able to create a custom menu by following the instructions
> > on the following awesome site:http://www.ozgrid.com/VBA/custom-menus.htm

>
> > What I am unable to do is to call the functions from the custom menu.

>
> > Each UDF has its own module in the xla workbook and starts with Public
> > Function <function name>(serial As String) As Integer

>
> > The OnAction line reads:

>
> > .OnAction = "<function name>()"

>
> > Error message that I get: The macro '<function name>()' cannot be
> > found

>
> > Can you please help me out what I do wrong and tell me what the
> > correct syntax for OnAction is?

>
> > I appreciate your help.

>
> Hi Dutch_Guy
>
> I'm not sure why your macros aren't working. Is the custom menu also
> created in the add-in? You should probably delete the parentheses from
> the string, because these can cause the function to be executed twice.
>
> I'm a bit confused by the part
>
> (serial As String) As Integer
>
> In your custom menu, how can you pass an argument in or use the
> result?
>
> If you want to do this, i would recommend that you write an
> intermediate function along the lines of:
>
> public sub Intermediate()
>
> dim intTemp as integer
>
> intTemp = OriginalFunctionName("serialstring")
>
> 'do something with intTemp
>
> end sub
>
> Then in your menu, call
>
> .OnAction = "Intermediate"
>
> Hope this helps
>
> Laura

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call user defined function in an add-in =?Utf-8?B?RGFsZSBGeWU=?= Microsoft Excel Programming 2 15th Dec 2006 05:04 PM
Not able to call a function from custom menu item that is added in word menu(File) jayrm100@yahoo.com Microsoft Word Document Management 0 9th Nov 2005 05:36 AM
Call GoalSeek from a user-defined-function =?Utf-8?B?TWFyaw==?= Microsoft Excel Programming 1 23rd Aug 2005 01:50 PM
Call Link to MS Word from a User-defined Menu =?Utf-8?B?TFBD?= Microsoft Access Database Table Design 4 13th Jan 2005 06:43 AM
Call user defined word vba function from C# AP Microsoft C# .NET 1 29th Oct 2003 11:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:10 PM.