Docs API Reference

Bindings.addFromPromptAsync method

Displays UI that lets the user specify a selection to bind to.

Hosts: Access, Excel
Available in Requirement set Not in a set
Last changed 1.1
_bindingsObj.addFromPromptAsync(bindingType [, options], callback);

Parameters

Name Type Description Support notes
bindingType BindingType Specifies the type of the binding object to create. Required. Returns null if the selected object cannot be coerced into the specified type.
options object Specifies any of the following optional parameters.
id string Specifies the unique name to be used to identify the new binding object.If no argument is passed for the id parameter, the Binding.id is autogenerated.
promptText string Specifies the string to display in the prompt UI that tells the user what to select. Limited to 200 characters. If no promptText argument is passed, "Please make a selection" is displayed.
sampleData TableData Specifies a table of sample data displayed in the prompt UI as an example of the kinds of fields (columns) that can be bound by your add-in. The headers provided in the TableData object specify the labels used in the field selection UI. Optional. Note: This parameter is used only in add-ins for Access. It is ignored if provided when calling the method in an add-in for Excel.
asyncContext array, boolean, null, number, object, string, or undefined A user-defined item of any type that is returned in the AsyncResult object without being altered.
callback object A function that is invoked when the callback returns, whose only parameter is of type AsyncResult.

Callback Value

When the function you passed to the callback parameter executes, it receives an AsyncResult object that you can access from the callback function's only parameter.

In the callback function passed to the addFromPromptAsync method, you can use the properties of the AsyncResult object to return the following information.

Property Use to...
AsyncResult.value Access the Binding object that represents the selection specified by the user.
AsyncResult.status Determine the success or failure of the operation.
AsyncResult.error Access an Error object that provides error information if the operation failed.
AsyncResult.asyncContext Access your user-defined object or value, if you passed one as the asyncContext parameter.

Remarks

Adds a binding object of the specified type to the Bindings collection, which will be identified with the supplied id. The method fails if the specified selection cannot be bound.

Example

function addBindingFromPrompt() {

    Office.context.document.bindings.addFromPromptAsync(Office.BindingType.Text, { id: 'MyBinding', promptText: 'Select text to bind to.' }, function (asyncResult) {
        write('Added new binding with type: ' + asyncResult.value.type + ' and id: ' + asyncResult.value.id);
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

Support details

A capital Y in the following matrix indicates that this method is supported in the corresponding Office host application. An empty cell indicates that the Office host application doesn't support this method.

For more information about Office host application and server requirements, see Requirements for running Office Add-ins.

Office for Windows desktop Office Online (in browser) Office for iPad
Access Y
Excel Y Y Y
Available in requirement sets Not in a set
Minimum permission level ReadDocument
Add-in types Content, task pane
Library Office.js
Namespace Office

Support history

Version Changes
1.1 Added support for Excel in Office for iPad.
1.1 In add-ins for Excel, you can create a table binding (passing bindingType as Office.BindingType.Table) for a range of cells that contains tabular data even when that data was not added to the spreadsheet as a table in the Excel UI (by using the Insert > Tables > Table or Home > Styles > Format as Table commands).
1.1 Added support for table binding in content add-ins for Access.
1.1 Added support for binding to matrix data as a table binding in add-ins for Excel.
1.0 Introduced