Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my code is
VB
Dim oApp As New Excel.Application()
        Dim wb As Excel.Workbook
        Dim oldCI As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
        System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
        wb = oApp.Workbooks.Open("D:\NoriaMail\23120011\LPO Summary per Month_View 3 - All Months.xlsx")
        'oApp.Workbooks.
        System.Threading.Thread.CurrentThread.CurrentCulture = oldCI
        oApp.Visible = False
        Dim cmdText As String
        Dim cmdType
        Dim connStr
        cmdText = wb.Connections.Item(1).OLEDBConnection.CommandText
        cmdType = wb.Connections.Item(1).OLEDBConnection.CommandType
        wb.Connections.Item(1).Delete()
        connStr = "OLEDB;Provider=SQLOLEDB.1;" & _
                        "Password=sa;" & _
                        "Persist Security Info=True;" & _
                        "User ID=sa;" & _
                        "Initial Catalog=Northwind;Data Source=."
        wb.Connections.Add("NORIA", "", connStr, cmdText, 2)
        wb.RefreshAll()
        'wb.Close(False)
        wb = Nothing
        oApp = Nothing
        ' oApp.Quit()
        GC.Collect()
        'wb.Close(True, "D:\NoriaMail\23120011\LPO Summary per Month_View 3 - All Months.xlsx", False)
        'oApp.Visible = False
        WebBrowser1.Navigate("D:\NoriaMail\23120011\LPO Summary per Month_View 3 - All Months.xlsx")
        'oApp.Visible = False
    End Sub

//I have three problems
1-I want to change
wb = oApp.Workbooks.Open("D:\NoriaMail\23120011\LPO Summary per Month_View 3 - All Months.xlsx")
with another method to initialize wb without open the excel file
2-how can I close the file with saving my configuration but without let the excel file to ask me if I want to save my change.
3-realize wb from the memory and all thing connection with it.
please any help
Posted

1 solution

If I understand correctly your question, #2 should be pretty straightforward, as the Workbook.Close method has an optional parameter SaveChanges. HTH.

http://msdn.microsoft.com/es-es/library/microsoft.office.tools.excel.workbook.close(v=vs.80).aspx[^]

in youe code you invoke wb.close twice, both are commented... but the second call is made after you set wb to nothing... i don't know why
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900