Consulting

Results 1 to 3 of 3

Thread: Button from Ribbon UI should call VBA function

  1. #1
    VBAX Newbie
    Joined
    Dec 2022
    Posts
    2
    Location

    Button from Ribbon UI should call VBA function

    Hello All,
    I have a button in Word via VBA that saves the Word document back to a SQL database.

    Here is the button definition so far:

    Set oCommandBar = CommandBars.Add(Name:="Exp", Position:=msoBarTop)
    oCommandBar.Visible = True
       
    Set oMenue = oCommandBar.Controls.Add(Type:=msoControlButton)
    With oMenue
                    .Caption = "Speichern nach Exp ..."
                    .Style = msoButtonCaption 
                    .OnAction = "SendToExp"
                    .Visible = True
                End With
    OnAction calls the function

    Public Function SendToExp() As String
        Dim httpreq As MSXML2.XMLHTTP30
        Dim Data As String
        Dim prop As DocumentProperty
        Dim url As String
    ........
    End Function
    This has also worked flawlessly for years. Now I wanted to add a second button that also saves back a PDF.
    Since I had to work on the macro anyway, I wanted to change the buttons to a modern ribbon UI.

    New Ribbon UI XML

    <customUI xmlns="Link office /2009/07/ customui">
        <ribbon startFromScratch="false">
      <tabs>
       <tab id="customTab" label="Justus Tab">
        <group id="customGroup" label="Justus Group">
         <button id="customButton" label="Exp1" imageMso="FileSave" size="normal" onAction="Messagebox" />
         <button id="customButton2" label="Exp2" imageMso="FileSave" size="normal" onAction="SendToExp" />
        </group>
       </tab>
      </tabs>
        </ribbon>
    </customUI>
    The button for the message box works:

    Sub Messagebox(control As IRibbonControl)
       MsgBox("Hallo")
    End Sub
    When pressing the SendToExp button, an error occurs:

    "Incorrect number of arguments or invalid assignment of a property".

    Public Function SendToExp(control As IRibbonControl) As String
    ......
    End Function
    Can someone tell me how the call must be directed?

    Best thanks and many greetings

    Markus
    Last edited by Paul_Hossler; 12-14-2022 at 09:02 AM. Reason: Added CODE tags

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,413
    Location
    Callbacks have a very specific format

    SendToExp MUST look like this since it's a Button callback. I usually use a global variable to hold any results, like file name.

    Sub Messagebox(control As IRibbonControl)
    
    Sub SendToExp(control As IRibbonControl)
    
    
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Newbie
    Joined
    Dec 2022
    Posts
    2
    Location
    Thanks for your help, problem solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •