If IsOpen(var) And System.IO.File.Exists(var) Then 'si fichier Existant ET ouvert MsgBox("Impossible d'enregistrer sur cet emplacement le fichier est déjà ouvert.", vbOKOnly + vbInformation, "ERREUR FICHIER OUVERT") xlsclasseur.Close(False) 'on ne sauvegarde pas les modifs xls = Nothing Else If var <> "" Then xlsclasseur.SaveAs(var) xlsclasseur.Close() MsgBox("EXPORTATION REUSSI", vbOKOnly + vbInformation, "FABRICATION 2013") System.Diagnostics.Process.Start(var) 'ouverture du xls créé End If xls = Nothing Fab_main.Close() Close() End If
xls.SaveWorkspace("c:\test.xls")
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionSaveFileDialog_test.Filter = "Fichiers excel (*.xls)|*.xls" SaveFileDialog_test.Title = "DIALOG1" SaveFileDialog_test.ShowDialog() var = SaveFileDialog_test.FileName If IsOpen(var) And System.IO.File.Exists(var) Then MsgBox("Impossible d'enregistrer sur cet emplacement le fichier est déjà ouvert.", vbOKOnly + vbInformation, "ERREUR FICHIER OUVERT") Else If var <> "" Then xlsclasseur.SaveAs(var) xlsclasseur.Close() End If xls.Application.Quit() xls = Nothing MsgBox("EXPORTATION REUSSI", vbOKOnly + vbInformation, "FABRICATION 2013") System.Diagnostics.Process.Start(var) 'ouverture du xls créé Fab_main.Close() Close() End If
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Dim oXL As Excel.Application Dim oWB As Excel.Workbook Dim oSheet As Excel.Worksheet oXL = CreateObject("Excel.Application") oWB = oXL.Workbooks.Add oSheet = oWB.ActiveSheet oSheet.Cells(1, 1).Value = "toto" oXL.SaveWorkspace() oSheet = Nothing oWB = Nothing oXL.Quit() oXL = Nothing End Sub
que j'ai faites à partir de divers copier coller sans forcement comprendra la logique .
Dans une de mes fonctions qui me remplit un fichier xls depuis une base sql
'declaration Dim xls As Excel.Application Dim xlsfeuille As Excel.Worksheet Dim xlsclasseur As Excel.Workbook xls = CreateObject("Excel.Application") xlsclasseur = xls.Workbooks.Add xlsfeuille = xlsclasseur.Worksheets(1) For Each Ligne As DataRowView In NB_V_M_date_view xlsfeuille.Cells(i, "B").value = Ligne("artnrlev").ToString xlsfeuille.Cells(i, "C").value = Ligne("artnr").ToString xlsfeuille.Cells(i, "D").value = Ligne("artbeskr").ToString i = i + 1 Next Catch ex As Exception MsgBox(ex.Message) End Try 'remplissage entête 'xlsfeuille.Cells(1, "E").value = pub_Designation xlsfeuille.Cells(1, "A").Value = "Quantité" xlsfeuille.Cells(1, "B").Value = "Référence fournisseur" xlsfeuille.Cells(1, "C").value = "N° Article" xlsfeuille.Cells(1, "D").value = "Desc article" xlsfeuille.Cells(1, "E").value = "Desc article cde " ' mr.ordartbeskr xlsfeuille.Cells(1, "F").value = "Texte specifique commande" 'mr.orpradtexte xlsfeuille.Cells(1, "G").value = "??" xlsfeuille.Cells(1, "H").value = "Dimension 1 " 'mr.dimension1 xlsfeuille.Cells(1, "I").value = "Dimension 2 " 'mr.dimension 2 'xls_a_remplir.Cells(1, "E").value = Requete 'boite de sauvegarde SaveFileDialog_test.Filter = "Fichiers excel (*.xls)|*.xls" SaveFileDialog_test.Title = "Sauvegarde Config" SaveFileDialog_test.ShowDialog() var = SaveFileDialog_test.FileName If IsOpen(var) And System.IO.File.Exists(var) Then 'si fichier Existant ET ouvert MsgBox("Impossible d'enregistrer sur cet emplacement le fichier est déjà ouvert.", vbOKOnly + vbInformation, "ERREUR FICHIER OUVERT") Else If var <> "" Then xlsclasseur.SaveAs(var) xlsclasseur.Close() MsgBox("EXPORTATION REUSSI", vbOKOnly + vbInformation, "FABRICATION 2013") End If xls.Application.Quit() xls = Nothing System.Diagnostics.Process.Start(var) 'ouverture du xls créé Fab_main.Close() Close() End If
Private Sub Remplissage(ByVal Dataset_result As DataSet, ByVal Dataset_op As DataSet, ByVal Dataset_caisson As DataSet) Dim xls As Excel.Application Dim xlsfeuille As Excel.Worksheet Dim xlsclasseur As Excel.Workbook Dim var As String Dim i As Integer Dim loc_antal, loc_formule As String Dim Nb_V_F_data_view, NB_V_M_data_view As New DataView(Dataset_result.Tables("Materiel")) Dim Type_Op_data_view As New DataView(Dataset_op.Tables("materiel")) Dim caisson_data_view As New DataView(Dataset_caisson.Tables("materiel")) Dim SaveFileDialog_test As New SaveFileDialog() xls = CreateObject("Excel.Application") xlsclasseur = xls.Workbooks.Add xlsfeuille = xlsclasseur.Worksheets(1) xlsfeuille.Name = "Config" SaveFileDialog_test.Filter = "Fichiers excel (*.xls)|*.xls" SaveFileDialog_test.Title = "Sauvergarde Config" SaveFileDialog_test.ShowDialog() var = SaveFileDialog_test.FileName If IsOpen(var) And System.IO.File.Exists(var) Then 'si fichier Existant ET ouvert MsgBox("Impossible d'enregistrer sur cet emplacement le fichier est déjà ouvert.", vbOKOnly + vbInformation, "ERREUR FICHIER OUVERT") Else If var <> "" Then xlsclasseur.SaveAs(var) xlsclasseur.Close() MsgBox("EXPORTATION REUSSI", vbOKOnly + vbInformation, "FABRICATION 2013") System.Diagnostics.Process.Start(var) 'ouverture du xls créé End If 'xls.Application.Quit() xls = Nothing Fab_main.Close() Close() End If End Sub