none
Remove Data Connection in Excel.

    Question

  • Hi All,

    I need your help on removing the connections for the archived excel.   I tried the below code.. once I ran the code and open the excel, it gives a warning "external data connection is disabled".. and I can able to see the connection under worksheet connections and definition also available. 

    Dim excelApp As New Application()
            Dim wb As Workbook = excelApp.Workbooks.Open(destination)

           
            If wb.Connections.Count > 0 Then
                For j As Integer = 1 To wb.Connections.Count
                    wb.Connections.Item(j).Delete()
                Next j
            End If

    Any help on this is much appreciated.

    Regards

    Madhavan.TR

     

    Madhavan Thasu Ramachandran

    Wednesday, August 28, 2013 7:24 PM

All replies

  • Hi Madhaven.TR,

    I can’t reproduce your issue on my lab machine (Windows 8+ Office 2013). I add code like below:

      Dim destination As String
    
    
            Dim excelApp As New Application()
    
            Dim wb As Workbook = excelApp.Workbooks.Open(destination)
    
    
    
            If wb.Connections.Count > 0 Then
    
                For j As Integer = 1 To wb.Connections.Count
    
                    wb.Connections.Item(j).Delete()
    
                Next j
    
            End If
    
            wb.Save()
    
    excelApp.Quit()
    

    BTW, which version of Office are you using?

    Thursday, August 29, 2013 12:43 PM