Share via


Workbook.Connections Property (2007 System)

Gets the collection of connections between the workbook and a data source.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)

Syntax

'Declaration
<BrowsableAttribute(False)> _
Public ReadOnly Property Connections As Connections
'Usage
Dim instance As Workbook 
Dim value As Connections 

value = instance.Connections
[BrowsableAttribute(false)]
public Connections Connections { get; }
[BrowsableAttribute(false)]
public:
property Connections^ Connections {
    Connections^ get ();
}
public function get Connections () : Connections

Property Value

Type: Connections
A Microsoft.Office.Interop.Excel.Connections collection that contains the connections between the workbook and a data source.

Examples

The following code example adds a new data connection to the specified CSV file. Next, the example iterates through all connections that exist in the workbook and displays the name, type, and description of each connection. This example requires a CSV file named SalesData.csv at the root of drive C. The CSV file should contain comma-separated data. When you run this example, Excel starts the Text Import Wizard; follow the steps in this wizard to create the data connection to the CSV file.

This example is for a document-level customization.

Private Sub WorkbookConnections()
    Dim myConnection As Excel.WorkbookConnection = _
        Me.Connections.AddFromFile("c:\SalesData.csv")
    myConnection.Description = "Data stored in a CSV file." 

    For Each connection As Excel.WorkbookConnection In Me.Connections
        MessageBox.Show(connection.Name + " " + connection.Type.ToString() _
            + " " + connection.Description)
    Next 
End Sub
private void WorkbookConnections()
{
    Excel.WorkbookConnection myConnection =
        this.Connections.AddFromFile(@"C:\SalesData.csv");
    myConnection.Description = "Data stored in a CSV file.";

    foreach (Excel.WorkbookConnection connection in this.Connections)
    {
        MessageBox.Show(
            "Connection Name: " + connection.Name 
            + "\r\nConnection Type: " + connection.Type.ToString()
            + "\r\nDescription: " + connection.Description);
    }
}

.NET Framework Security

See Also

Reference

Workbook Class

Workbook Members

Microsoft.Office.Tools.Excel Namespace