"fichier-DATE.xlsx"

Fermé
Visual Studio - 26 janv. 2012 à 16:57
cousinhub29 Messages postés 942 Date d'inscription mardi 10 août 2010 Statut Membre Dernière intervention 8 octobre 2024 - 26 janv. 2012 à 20:06
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.


A voir également:

1 réponse

cousinhub29 Messages postés 942 Date d'inscription mardi 10 août 2010 Statut Membre Dernière intervention 8 octobre 2024 343
Modifié par cousinhub29 le 26/01/2012 à 20:07
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