"fichier-DATE.xlsx"

Visual Studio -  
cousinhub29 Messages postés 1114 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour, chers gars
Je souhaite enregistrer automatiquement mon
fichier xlsx dans ce style:

Le point2012-01-14_1
Le point2012-01-14_2 lorsque le _1 vient à exister.

Le logiciel que je monte écrit dans un classeur excel.
Suivez plutot:

Private Sub yes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles yes.Click
        Dim oExcel As Object
        Dim oBook As Object
        Dim oSheet As Object


        'Start a new workbook in Excel
        oExcel = CreateObject("Excel.Application")
        oBook = oExcel.Workbooks.Add


        'Add data to cells of the first worksheet in the new workbook
        oSheet = oBook.Worksheets(1)

        oSheet.Range("A2").value = "Cyber"
        oSheet.Range("B2").Value = TB1.Text
        oSheet.Range("C2").Value = tb2.Text

        oSheet.Range("A3").value = "Photocopie"
        

        oSheet.Range("A5").value = "Saisie"

        oSheet.Range("A6").value = "Biscuit"

        oSheet.Range("A8").value = "              Total"
        oSheet.range("D1").Value = "              Total"
        oSheet.Range("A8").font.bold = True
        oSheet.Range("D8").Value = TextBox4.Text
        oSheet.Range("D8").font.bold = True
        oSheet.Range("D2").value = TextBox4.Text
        oSheet.Range("B1").Value = "             Matin"
        oSheet.Range("C1").Value = "                Soir"
        oSheet.Range("B1:C1: D1").Font.Bold = True

        'Save the Workbook and Quit Excel


        oBook.SaveAs("C:\Documents and Settings\Administrateur\Mes documents\Visual Studio 2010\Projects\Cyber Café\Caisse\Le point.xlsx")
        oExcel.quit()

        Dim form As New Form1
        Form1.Show()
        Me.Dispose()
    End Sub


Je sais qu'il faut agir sur Le point"......."xlsx mais comment?
Je vous remercie.

1 réponse

  1. cousinhub29 Messages postés 1114 Date d'inscription   Statut Membre Dernière intervention   380
     
    Bonsoir,

    Tu peux essayer ainsi

    Nota 1: si tu penses avoir plus de 255 fichiers, définis la variable X as integer
    Nota 2 : j'ai supposé que tous tes fichiers commençaient par "Le point_"

    Dim LePath As String, NomFich As String 
    Dim X As Byte 
    LePath = "C:\Documents and Settings\Administrateur\Mes documents\Visual Studio 2010\Projects\Cyber Café\Caisse\" 
    '.... 
    '.... 
    '.... 
    NomFich = Dir(LePath & "*.xlsx") 
    Do While NomFich <> "" 
        If NomFich Like "Le point_*" Then 
            X = X + 1 
        End If 
        NomFich = Dir 
    Loop 
    oBook.SaveAs (LePath & "Le point_" & X + 1 & ".xlsx") 
    '.... 
    '.... 
    '.... 
    


    Bonne soirée
    0