none
Change Excel defined connection to an access db RRS feed

  • Question

  • Hi, im using a C# program to add data to two tables.

    I want to change the path to the .accdb that are defined in the excel book.
    But i havent found a code to do so. (Using Office 2013).

    Anyone know how to open the .xlsx and change these connections (data, dataSorterad)?

    • Moved by CoolDadTx Wednesday, December 16, 2015 3:53 PM Office related
    Wednesday, December 16, 2015 11:57 AM

Answers

  • >>>I want to change the path to the .accdb that are defined in the excel book.
    But i havent found a code to do so. (Using Office 2013).

    According to your description, I suggest that you could use Connections Object (Excel) that is a collection of Connection objects for the specified workbook to get the WorkbookConnection object
    then change. you could refer to below VBA code then change into C#:

    Dim cn As WorkbookConnection
    Dim oledbCn As OLEDBConnection
    Set cn = ThisWorkbook.Connections("Connection Name")
    Set oledbCn = cn.OLEDBConnection
    oledbCn.Connection = ConnectionString

    For more information, click here to refer about Connections Object (Excel) and here to refer about WorkbookConnection Object (Excel)

    • Marked as answer by David_JunFeng Tuesday, December 29, 2015 2:44 PM
    Thursday, December 17, 2015 3:25 AM