How to register a macro

420 views
Skip to first unread message

carr...@gmail.com

unread,
Mar 19, 2016, 3:49:32 AM3/19/16
to Excel-DNA
I'm developing a macro with ExcelDna for Excel.
I want this macro to be listed together with other macros written in VBA in list "Developr - Macro" 

Below is my code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExcelDna.Integration;

namespace ClassLibrary1
{
    public class Class1
    {
        [ExcelFunction(IsMacroType=true)]
        public static void TestMacro()
        {
        }
    }
}

However, it fails to register.
Registration [Error] xlfRegister call failed for function or command: 'TestMacro'

Anyone has idea?
Thanks

Frank

Govert van Drimmelen

unread,
Mar 19, 2016, 8:23:14 AM3/19/16
to exce...@googlegroups.com
Hi Frank,

You need to mark the method with [ExcelCommand] instead of [ExcelFunction].

      [ExcelCommand(ShortCut = "^D")] // Press Ctrl+Shift+D to run
        public static void TestMacro()
        {
        }
That should clear the registration error. But it still won't who up in the Alt+F8 Macro dialog box - Excel considers macros in .xll add-ins as hidden. However, you can type the name into that dialog, and the "Run" button should light up and enable you to run the macro.

You can also assign the macro to a shortcut key as above, or a ribbon button when customizing the ribbon (it should appear on the macros list there).

-Govert




From: exce...@googlegroups.com [exce...@googlegroups.com] on behalf of carr...@gmail.com [carr...@gmail.com]
Sent: 19 March 2016 09:22 AM
To: Excel-DNA
Subject: [ExcelDna] How to register a macro

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.

carr...@gmail.com

unread,
Mar 20, 2016, 12:34:24 AM3/20/16
to Excel-DNA
I see.
Thank you very much.
To post to this group, send email to exc...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages