Ultima modifica di Paki243; 12-07-2016 a 16:06
Ha ragione Oregon sul fatto che il servizio EXCEL rimane attivo,infatti dopo il salvataggio,bisogna mettere la variabile Excel = nothing e dopo fare quit() per terminare EXCEL in memoria.
Lo potete anche leggere al link della Microsoft che vi ho inviato.
Ultima modifica di Paki243; 12-07-2016 a 16:13
Intanto ho configurato il nome della variabile sulla mia rubrica. Ho fatto quello che dice il sito Microsoft ma quando lo compilo,mi dice "Impossibile utilizzare oggetti COM separati dai relativi RCW sottostanti."
Ok ragazzi, mi dovrei vergognare, per ora ho aggiunto questa riga comando:
Shell("taskkill /F /IM EXCEL.EXE", AppWinStyle.Hide, False, 0)
E mi chiude l'applicazione... e FINE... appena troverò qualche alternativa Funzionale... la userò.
Anche perchè ho controllato tutto il codice... e non c'è nessuna istanza pendente quindi non riesco a capire!!!![]()
OK,ma l'alternativa ufficiale che chiude Excel esiste. CIAO![]()
Invece di usare il taskkill, mostra *tutto* il codice relativo ad Excel e a quello che fai con questo file e vediamo dove sta il problema
No MP tecnici (non rispondo nemmeno!), usa il forum.
Ragazzi non solo noi abbiamo questo problema. Vi ripeto guardate al link che ho inviato,c'é scritto come fare. Infatti manca come ho scritto prima bisogna comandare alla variabile l'uscita con quit e nothing. Vedete il link.
Il Codice è questo, sono nel mondo .NET da poche settimane quindi, non spaventatevi:
__________________________________________________ ___________________
Dim Col_mese As Integer = ComboBox1.SelectedIndex + 9
Dim XLS_Formula As String
xlApp = New Microsoft.Office.Interop.Excel.Application
SrcFile = TextBox1.Text
SrcFile2 = TextBox2.Text
DestFile = TextBox3.Text
If TextBox4.Text <> "" Then N_Row = TextBox4.Text Else N_Row = 2
If TextBox5.Text <> "" Then N_row2 = TextBox5.Text Else N_row2 = 2
If TextBox6.Text <> "" Then N_ROW3 = TextBox6.Text Else N_ROW3 = 2
Riga_int = N_Row - 1
Riga_Int2 = N_row2 - 1
Riga_Int3 = N_ROW3 - 1
Conta = 1
'CONTROLLO SE I FILE SONO GIUSTI
If (LCase(SrcFile) = LCase(SrcFile2)) Or LCase((LCase(SrcFile) = LCase(DestFile))) Or LCase((LCase(SrcFile2) = LCase(SrcFile))) Or LCase((LCase(DestFile) = LCase(SrcFile2))) Then
'If (SrcFile = SrcFile2) Or (SrcFile = DestFile) Or (SrcFile = DestFile) Or (DestFile = SrcFile2) Then
MsgBox("Hai Selezionato i file SORGENTI in modo errato!!!!" & vbCrLf & vbCrLf & "Loperazione sarà Terminata.", vbCritical, "ATTENZIONE!")
Exit Sub
End If
If IO.File.Exists(SrcFile) = False Then
MsgBox("IL FILE SELEZIONATO CON I DATI 'ORE' E' MANCANTE!!!" & vbCrLf & vbCrLf & "L'OPERAZIONE SARA' TERMINATA", vbCritical, "ATTENZIONE!!! FILE MANCANTE:")
Exit Sub
End If
If IO.File.Exists(SrcFile2) = False Then
MsgBox("IL FILE SELEZIONATO CON I DATI 'REPORT' E' MANCANTE!!!" & vbCrLf & vbCrLf & "L'OPERAZIONE SARA' TERMINATA", vbCritical, "ATTENZIONE!!! FILE MANCANTE:")
Exit Sub
End If
If IO.File.Exists(DestFile) = False Then
MsgBox("IL FILE SELEZIONATO COME MODELLO DATI E' MANCANTE!!!" & vbCrLf & vbCrLf & "L'OPERAZIONE SARA' TERMINATA", vbCritical, "ATTENZIONE!!! FILE MANCANTE:")
Exit Sub
End If
xlbook = xlApp.Workbooks.Open(SrcFile)
xlsheet = xlbook.Worksheets(1)
xlbook2 = xlApp.Workbooks.Open(SrcFile2)
xlsheet2 = xlbook2.Worksheets(1)
xlbook3 = xlApp.Workbooks.Open(DestFile)
xlsheet3 = xlbook3.Worksheets(1)
xlApp.Visible = False
Ok_Cod = ""
If xlsheet.Cells(Riga_Int, 1).Value <> "Codice Dipendente" Then
MsgBox("IL FILE SELEZIONATO CON I DATI 'ORE' E' ERRATO!!!", vbCritical, "ATTENZIONE!!! FILE ERRATO:")
Chiudi_XLS()
Exit Sub
ElseIf xlsheet2.Cells(Riga_Int2, 3).Value <> "Cod. Dip." Then
MsgBox("IL FILE SELEZIONATO CON I DATI 'REPORT ASSENTEISMO' E' ERRATO!!!", vbCritical, "ATTENZIONE!!! FILE ERRATO:")
Chiudi_XLS()
Exit Sub
ElseIf xlsheet3.Cells(Riga_Int3, 1).Value <> "cid cod identificativo" Then
MsgBox("IL FILE SELEZIONATO COME MODELLO DATI E' ERRATO!!!", vbCritical, "ATTENZIONE!!! FILE ERRATO:")
Chiudi_XLS()
Exit Sub
End If
Dim I As Integer
Do While Not (xlsheet2.Cells(N_row2, 1).Text = "" Or Strings.InStr(1, xlsheet2.Cells(N_row2, 1).Text, "Totale", CompareMethod.Text)) > 0
If N_row2 > 389 Then MsgBox(xlsheet2.Cells(N_row2, 1).Text & vbLf & Strings.InStr(xlsheet2.Cells(N_row2, 1).Text, "Totale"))
If xlsheet2.Cells(N_row2, 3).Value <> "*" Then
Cod_Dip = xlsheet2.Cells(N_row2, 3).Value
N_Row = 2
'MsgBox (xlsheet2.Cells(N_row2, 5).Value & " - " & cod_dip)
For I = Riga_int + 1 To 65535
Ok_Cod = "NO"
If IsNumeric(xlsheet.Cells(I, 1).Value) = False Then Cod_Dip_Confr = 0 Else Cod_Dip_Confr = xlsheet.Cells(I, 1).text
If Cod_Dip <> Cod_Dip_Confr Then
N_row2 = N_row2 + 1
Ok_Cod = "NO"
Else
Ok_Cod = "SI"
Exit For
End If
If xlsheet.Cells(I, 1).text.ToString = "" Then
Exit For
End If
Next I 'Loop
'OK, TROVATO
'If Ok_Cod = "SI" Then
'MsgBox(xlsheet.Cells(1, 10).text.ToString)
If xlsheet.Cells(Riga_int, Col_mese).text.ToString = ComboBox1.Text.ToString Then
xlsheet3.Cells(N_ROW3, 1).Value = Cod_Dip
xlsheet3.Cells(N_ROW3, 2).Value = xlsheet2.Cells(N_row2, 6).text.ToString
xlsheet3.Cells(N_ROW3, 3).Value = xlsheet2.Cells(N_row2, 7).text.ToString
xlsheet3.Cells(N_ROW3, 4).Value = xlsheet2.Cells(N_row2, 8).text.ToString
xlsheet3.Cells(N_ROW3, 5).Value = xlsheet2.Cells(N_row2, 9).text.ToString
xlsheet3.Cells(N_ROW3, 6).Value = xlsheet2.Cells(N_row2, 5).text.ToString
........
......
......
'29 % STRAORDINARIO SU H LAVORABILI
If xlsheet3.Cells(N_ROW3, 16).text.ToString = "" Or xlsheet3.Cells(N_ROW3, 16).text.ToString = "0" Then
XLS_Formula = "0"
Else
XLS_Formula = "=(" & xlsheet3.Cells(N_ROW3, 12).Address & "+" & xlsheet3.Cells(N_ROW3, 13).Address & ")/" & xlsheet3.Cells(N_ROW3, 16).Address
End If
xlsheet3.Cells(N_ROW3, 29).Formula = XLS_Formula
xlsheet3.Range(xlsheet3.Cells(N_ROW3, 29).Address).NumberFormat = "0.00%"
........
......
......
xlsheet3.Cells(N_ROW3, 34).Formula = XLS_Formula
xlsheet3.Range(xlsheet3.Cells(N_ROW3, 34).Address).NumberFormat = "0.00%"
N_ROW3 = N_ROW3 + 1
Else
MsgBox(UCase("Attenzione Mese non presente nel file sorgente!..." & vbCrLf & vbCrLf & "Il Programma Verrà Terminato."), vbCritical, "ESITO IMPORTAZIONE FILE:")
xlbook.Close()
xlbook2.Close()
xlbook3.Close()
xlApp.Workbooks.Close()
Chiudi_XLS()
Exit Sub 'End
End If
End If
N_Row = N_Row + 1
Label5.Text = "Righe Elaborate : " & Conta & vbLf & "Righe inserite : " & N_ROW3 - 2
Label5.Refresh()
'----------------------------------------
'--- da togliere
'If Conta >= 10 Then Exit Do
'----------------------------------------
'----------------------------------------
Label9.Refresh()
Conta = Conta + 1
Loop
SaveFileDialog1.FileName = "INAZ_" & Strings.UCase(ComboBox1.Text) & "_" & Format(Now, "yyyyMMddHHmm") & ".xlsx"
SaveFileDialog1.Filter = "File Excel | *.XL*"
SaveFileDialog1.InitialDirectory = Application.StartupPath & "\DOC\"
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName.ToString = "" Then
Filename = Application.StartupPath & "\DOC\Assenteismo_x_INAZ_" & Strings.UCase(ComboBox1.Text) & "_" & Format(Now, "yyyyMMddHHmm") & ".xlsx"
Else
Filename = SaveFileDialog1.FileName.ToString
End If
xlbook3.SaveAs(Filename)
'xlbook3.Save()
Chiudi_XLS()
Risp = MsgBox("OPERAZIONE TERMINATA CON SUCCESSO...! Vuoi Aprire il file Appena Creato?", vbYesNo + vbInformation, "ESITO CREAZIONE DILE FILE:")
If Risp = vbYes Then
Process.Start(Filename)
End If
__________________________________________________ ___________________
Grazie Oregon.
L'articolo a cui ti riferisci riguarda l'ambiente Microsoft Excel, non VB.NET.
Quindi non ha alcun impiego in VB.NET
In questo progetto:
http://nuke.vbcorner.net/Projects/NE...S/Default.aspx
si vede, oltre ad altre cose molto interessanti, come chiudere Excel correttamente.
![]()
Ultima modifica di gibra; 13-07-2016 a 10:49