> For the complete documentation index, see [llms.txt](https://docs.xlconnect.net/xlconnect-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.xlconnect.net/xlconnect-documentation/developing-with-xlconnect/vba.md).

# VBA

Control scripts from VBA

The XLConnect add-in can be controlled from VBA for a better user experience when users click on a button, doubleclick a cell, change a value etc.

Below is an example that runs the script named "Pull TrialBalance"

```
Sub PullConnections()
    Set xlc = Application.COMAddIns("XLConnect").Object
    xlc.fetchData "Pull TrialBalance"
End Sub
```

## To use this in your workbook:

* [Import script ](/xlconnect-documentation/developing-with-xlconnect/import-scripts.md)"Connections"
* On the `Insert` ribbon of Excel, insert an Icon
* Right-click the icon and select `Assign Macro...`
* In the Assign Macro screen, select `New`

<figure><img src="https://2187688023-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMwwg2EqgR32FSkJdVLhw%2Fuploads%2FE4jbAwq1LZzPMAoJtgiG%2Fimage.png?alt=media&amp;token=f4ac1efb-9422-4bf4-abc6-f01d91146720" alt=""><figcaption></figcaption></figure>

* This should bring you to the VBA editor. If not, press ALT-F11.
* Paste in the two lines so your code looks like this:

```
Sub Graphic2_Click()
    Set xlc = Application.COMAddIns("XLConnect").Object
    xlc.fetchData "Connections"
End Sub
```

Make sure the name of the VBA method corresponds to the name in the `Assign Macro` editor in Excel (in this case `Graphic2_Click`).

* Go back to Excel and click the icon, that should now run the Graphic2\_Click VBA method, that will execute the Connections script.

This is how simple it is to execute a script by clicking an icon.

## Available methods
