Unlink data from Excel sheet

Hoogie

Member
Joined
Jan 22, 2014
Messages
12
Programming Experience
1-3
I'm designing a program that runs a Excel query file (.dqy), edits the information by adding mathematical columns, and saves the Excel file. That all works, however I would like to unlink the data connection to the saved file, and I am unsure on how to do that without using sendkey commands (which I would rather not do if preventable). Any help would be appreciated.

VB.NET:
        appXL = CreateObject("Excel.Application")        
        appXL.Visible = True
        ' Open a new workbook.
        wbXl = appXL.Workbooks.Open("C:\Employees.dqy")
        shXL = wbXl.ActiveSheet


        ' Add table headers going cell by cell.
        shXL.Cells(1, 5).Value = "Math Test"


        ' Fill C2:C6 with a relative formula (=A2 & " " & B2).
        raXL = shXL.Range("E2", "E6")
        raXL.Formula = "=A2 + B2"


        ' AutoFit columns A:D.

        raXL = shXL.Range("A1", "E1")
        raXL.EntireColumn.AutoFit()
        'Make sure Excel is visible and give the user control
        'of Excel's lifetime.
        appXL.Visible = True
        appXL.UserControl = True
        ' Release object references.

'NEED CODE HERE TO UNLINK DATA BEFORE SAVING.


        wbXl.SaveAs("C:\TEST.xlsx")
        raXL = Nothing
        shXL = Nothing
        wbXl = Nothing
        appXL.Quit()
        appXL = Nothing
        Exit Sub
 
Try recording a macro in Excel and perform the task manually, then look at the code. The .Net automation code is usually pretty close to that.
 
Back
Top