Chiudere Excel senza salvare

giovedì 12 luglio 2007 - 10.00

motodriver2002 Profilo | Newbie

Salve a tutti,

in una windows application ho scritto:

Dim xls As Microsoft.Office.Interop.Excel.Application
xls = New Microsoft.Office.Interop.Excel.Application
xls.Workbooks.Open("C:\Temp\ARCHIVIO\WORK\work.xls")
Dim sheetName As String
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
xlSheet = xls.Worksheets.Item(1)
sheetName = xlSheet.Name
xlSheet = Nothing
xls.Workbooks.Close()
xls.Quit()
xls = Nothing

Andando in debug, quando arrivo all'istruzione
xls.Workbooks.Close()
una messagebox mi chiede se voglio salvare il file oppure no.
C'è un modo per dirgli automaticamente di non salvare ed evitare che venga fuori questo messaggio?

Grazie a tutti.

Ciciu Profilo | Senior Member

Ciao.

Purtroppo non ho modo di provare fisicamente la cosa, però, e qui vado a memoria, una delle proprietà della Tua applicazione Excel dovrebbe essere DisplayAlert.
Se la poni a False, non dovrebbe più chiederTi nulla...


>Dim xls As Microsoft.Office.Interop.Excel.Application
>xls = New Microsoft.Office.Interop.Excel.Application
>xls.Workbooks.Open("C:\Temp\ARCHIVIO\WORK\work.xls")

' Questa è la riga da aggiungere.
xls.DisplayAlert = False;

> Dim sheetName As String
>Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
> xlSheet = xls.Worksheets.Item(1)
> sheetName = xlSheet.Name
> xlSheet = Nothing
> xls.Workbooks.Close()
> xls.Quit()
> xls = Nothing
>


Ciao - FabioG
Fabio G

motodriver2002 Profilo | Newbie

Funziona parfettamente.

Era proprio quell'impostazione DisplayAlert = false che mi serviva.

Grazie mille.
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5