tooltip in VBA

fayez rawashdeh 0 نقاط السُمعة
2026-01-01T21:40:08.9133333+00:00

I created a function in VBA, and this function has the following structure: `function total(a as double, b as double) as double

end function`. The requirement is that when this function is called in Excel, an explanation or comment should appear so that the user understands why this function is being used and what each of its variables does. Specifically, when I call an IF function, for example, a yellow bar should appear containing a description of the function and its variables.

How can I achieve this?

Microsoft 365 وOffice | Excel | للمنزل | Windows
0 تعليقات ليست هناك تعليقات

2 إجابات

فرز حسب: الأكثر فائدة
  1. Kai-H 21,620 نقاط السُمعة فريق عمل موظفين Microsoft الخارجيين المشرف
    2026-01-02T06:53:54.7866667+00:00

    Please note that this is Arabic Q&A Forum, any threads should be posted in Arabic. However, I will still provide an answer on English based on your initial response.

    Hi, fayez rawashdeh

    Thanks for reaching out to Microsoft Q&A forum.

    I appreciate your question. You can add function and argument help for a VBA UDF using Application.MacroOptions. This lets Excel show your description in the Insert Function (Fx) dialog and display argument names in the Function Arguments window, which are similar to built‑in functions. Inline “yellow bar” tooltips while typing are limited for VBA UDFs, but you can get close.

    Here are the workarounds you can try to achieve this:

    1) Define your UDF

    ' In a standard module
    Public Function total(a As Double, b As Double) As Double
        total = a + b
    End Function
    

    2) Register help text and argument descriptions

    Run a small macro once (e.g., on Workbook_Open) to attach descriptions:

    ' In ThisWorkbook
    Private Sub Workbook_Open()
        ' Register function metadata: description, category, and argument help
        Application.MacroOptions _
            Macro:="total", _
            Description:="Returns the sum of a and b. Use for quick numeric totals.", _
            Category:="User Defined", _
            ArgumentDescriptions:=Array( _
                "a: First addend (Double).", _
                "b: Second addend (Double)." _
            )
    End Sub
    ``
    

    Notes

    • Description shows in the Insert Function dialog when users pick your UDF.
    • ArgumentDescriptions appear in the Function Arguments dialog for your UDF.
    • Category can be a built‑in category number or a string (creates a custom category).

    If you don’t want it to run at open, you can execute the registration once from a normal macro. Excel persists these settings in the workbook, which then you don’t need to run the macro every time (but it applies per‑workbook, not globally).

    1. Get argument names into the formula quickly

    While typing a formula, Excel won’t show a rich UDF tooltip like built‑ins, but it can insert argument placeholders:

    • Type =total and press Tab > Excel enters =total(.
    • Press Ctrl+Shift+> Excel inserts =total(a, b) so users see the parameters.

    This is a handy way to mimic the guidance that the yellow bar gives for built‑in functions.

    4) Optional: Link to a Help file

    If you maintain a Help file, you can wire it up:

    Application.MacroOptions _
        Macro:="total", _
        HelpFile:="C:\Path\to\YourHelp.chm", _
        HelpContextID:=1001
    

    This enables “Help on this function” from relevant UI surfaces.

    5) Platform considerations (Windows vs. Mac)

    Historically, Excel for Mac has partial support for Application.MacroOptions. The Fx dialog shows UDFs, but some metadata (category mapping, inline tips) can be inconsistent on certain versions; you may need to run the registration macro in each workbook and re‑open to see changes in Formula Builder.

    6) What you cannot do with pure VBA

    The inline yellow ScreenTip that shows syntax and argument descriptions for built‑in functions is not fully available to VBA UDFs. You’ll get the Insert Function/Arguments dialogs and the Ctrl+Shift+A placeholders, but not the same rich, dynamic tooltip while typing. For truly rich inline tooltips, you’d need an XLL/COM add‑in or newer extensibility approaches beyond VBA.

    Hope this helps. Feel free to get back if you need further assistance.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment."    

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 

    هل كانت هذه الإجابة مفيدة؟

    شخص واحد وجد هذه الإجابة مفيدة.

  2. سالم صالح المالكي 1,135 نقاط السُمعة
    2026-05-26T13:21:35.9333333+00:00

    السلام عليكم ورحمة الله وبركاته

    أهلاً بك أخي فايز. إظهار شريط التلميحات الديناميكي الأصفر (Inline Tooltip) أثناء كتابة الدوال المخصصة (UDF) في محررات VBA يُعد من القيود التاريخية في بيئة إكسل التقليدية، حيث أن نظام التلميحات التلقائي مخصص فقط للدوال المبنية داخلياً في النظام (Built-in Functions).

    ولكن، يمكنك تحقيق نتيجتك ومساعدة المستخدمين على فهم متغيرات الدالة عبر الطرق الالتفافية المعتمدة التالية:

    #### أولاً: تسجيل وصف الدالة والمتغيرات عبر كود (Application.MacroOptions)

    هذا هو الحل البرمجي الأفضل، حيث يجعل الوصف يظهر للمستخدم فور فتح نافذة وسيطات الدالة (Fx):

    1. انسخ الكود التالي وضعه داخل حدث فتح كتاب العمل ThisWorkbook:

    ```vba

    Private Sub Workbook_Open()

    **Application.MacroOptions _**
    
        **Macro:="total", _**
    
        **Description:="تقوم هذه الدالة بحساب المجموع الإجمالي للقيم الإدخالية.", _**
    
        **Category:="User Defined", _**
    
        **ArgumentDescriptions:=Array("الرقم الأول المراد جمعه", "الرقم الثاني المراد جمعه")**
    

    End Sub

    ```

    2. عند قيام المستخدم بالضغط على زر دمج الدوال (Fx) واختيار دالتك total، سيظهر له شرح كامل لكل متغير وأهميته أسفل الصندوق.

    #### ثانياً: الاختصار الذكي أثناء الكتابة (Ctrl + Shift + A)

    *** لتبسيط الأمر على المستخدم أثناء الكتابة مباشرة داخل الخلية؛ بمجرد أن يكتب اسم الدالة ويفتح القوس كالتالي: =(total**

    *** اطلب منه الضغط على أزرار (Ctrl + Shift + A) في لوحة المفاتيح.**

    *** سيقوم إكسل تلقائياً بإدراج أسماء المتغيرات كـ (Placeholders) داخل الخلية ليعرف المستخدم ماذا يكتب (مثال: total(a, b)).**

    #### ثالثاً: الحل المتقدم (إضافات XLL / COM)

    إذا كنت تبحث عن تلميحات حية تظهر باللون الأصفر تماماً مثل دالة IF أثناء الكتابة الحرة، فإن بيئة VBA الصرفة لا تدعم ذلك. يتطلب الأمر بناء الإضافة باستخدام لغات برمجة أحدث مثل C# أو استخدام تقنيات (Excel-DNA) لإنشاء ملفات من نوع .XLL تدعم الخصائص المتطورة للإصدارات الحديثة من Microsoft 365.

    أتمنى أن تكون هذه الخيارات واضحة وتساعدك في تحسين تجربة استخدام دالتك المخصصة!

    بالتوفيق لك

    هل كانت هذه الإجابة مفيدة؟

    0 تعليقات ليست هناك تعليقات

إجابتك

يمكن وضع علامة على الأجوبة 'كمقبولة' من قبل كاتب السؤال و'مستحسنة' من قبل المشرفين، مما يساعد المستخدمين على معرفة الإجابة التي حلت مشكلة الكاتب.