Consulting

Results 1 to 3 of 3

Thread: Button from Ribbon UI should call VBA function

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

Posting Permissions

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