IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

FileSearch sous Excel 2007


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Octobre 2005
    Messages
    19
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 19
    Par défaut FileSearch sous Excel 2007
    j'ai lu cette discussion, mais dans mon cas vos solutions ne marche pas.

    J'ai une macro qui permet de créer un fichier automatiquement a partie d'un modèle si il n'existe pas. Auriez vous une solution fonctionelle sur 2007 et antérieurs ?

    Merci pour vos réponses.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    Sub lance()
     
    For i = 1 To Selection.Count
    ligne = Selection.Cells(i, 1).Row
    nom = "prix_" + ActiveCell.Text + ".xls"
                With fs
                    .Folderpath = ActiveWorkbook.Path
                    .Filename = nom
                    If .Execute() <> 0 Then
                    If .FoundFiles(1) = ActiveWorkbook.Path + "\" + nom Then
                    form = "='" + ActiveWorkbook.Path + "\[" + nom + "]prix_" + ActiveCell.Text + "'!$K$33"
                    Workbooks.Open Filename:=ActiveWorkbook.Path + "\" + nom
                    End If
                Else
                    Workbooks.Open Filename:=ActiveWorkbook.Path + "\prix_type.xls"
                    ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path + "\" + nom
                    Mid(nom, Len(nom) - 3, 4) = "    "
                    ActiveSheet.Name = RTrim(nom)
                    ActiveSheet.Cells(4, 2).Formula = Right(nom, Len(nom) - 5)
                    ActiveWorkbook.Save
                End If
                End With
    Next
    End Sub
    Sub imprime()
    Set fs = ClFileSearch.ClasseFileSearch
    For i = 1 To Selection.Count
    ligne = Selection.Cells(i, 1).Row
    nom = "prix_" + ActiveCell.Text + ".xls"
                With fs
                    .LookIn = ActiveWorkbook.Path
                    .Filename = nom
                    .MatchTextExactly = True
                If .Execute() = 1 Then
                    If .FoundFiles(1) = ActiveWorkbook.Path + "\" + nom Then
                    form = "='" + ActiveWorkbook.Path + "\[" + nom + "]prix_" + ActiveCell.Text + "'!$K$33"
                    Workbooks.Open Filename:=ActiveWorkbook.Path + "\" + nom
                    ActiveWorkbook.ActiveSheet.PrintOut
                    ActiveWorkbook.Saved = True
                    ActiveWorkbook.Close
                    End If
                End If
                End With
    Next
    End Sub

  2. #2
    Expert confirmé

    Homme Profil pro
    Inscrit en
    Août 2005
    Messages
    3 317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2005
    Messages : 3 317
    Par défaut
    bonsoir Laurent

    Relit le tutoriel. Tu confonds l'objet FileSearch et le complément, dans la syntaxe de ta procédure.


    un exemple simple à adapter à ta macro:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    Dim Fs As ClFileSearch.ClasseFileSearch
    Dim i As Long
    Dim Fichier As String, Chemin As String
    Dim Wb As Workbook
     
    Set Fs = ClFileSearch.Nouvelle_Recherche
    Chemin = ActiveWorkbook.Path
     
    With Fs
        .FolderPath = Chemin
        .SubFolders = False
        '.SortBy = sort_Name
        .Extension = "*NomClasseur.xls"
        .Execute
     
        For i = 1 To .FoundFilesCount
            Set Wb = Workbooks.Open(Chemin & "\" & .Files(i).strFileName)
            '
            'Action dans le(s) classeur(s)
            '
            Wb.Close (False)
        Next i
     
    End With


    bonne soirée
    michel

  3. #3
    Membre averti
    Inscrit en
    Octobre 2005
    Messages
    19
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 19
    Par défaut
    je suis débuttant et je ne comprend pas tous votre procédure. Je vais essayer mais tous vos conseils me seront utile.

  4. #4
    Membre averti
    Inscrit en
    Octobre 2005
    Messages
    19
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 19
    Par défaut
    la copie de mon code est erroné, elle comprend deja un essai de modi. Je vous rejoint mon code d'origine fonctionnel sous excel 2003



    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    Sub lance()
    Dim i As Long
    For i = 1 To Selection.Count
    ligne = Selection.Cells(i, 1).Row
    nom = "prix_" + ActiveCell.Text + ".xls"
                With Application.FileSearch
                    .LookIn = ActiveWorkbook.Path
                    .Filename = nom
                    .MatchTextExactly = True
                     If .Execute() <> 0 Then
                        If .FoundFiles(1) = ActiveWorkbook.Path + "\" + nom Then
                        form = "='" + ActiveWorkbook.Path + "\[" + nom + "]prix_" + ActiveCell.Text + "'!$K$33"
                        Workbooks.Open Filename:=ActiveWorkbook.Path + "\" + nom
                        End If
                    Else
                        Workbooks.Open Filename:=ActiveWorkbook.Path + "\prix_type.xls"
                        ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path + "\" + nom
                        Mid(nom, Len(nom) - 3, 4) = "    "
                        ActiveSheet.Name = RTrim(nom)
                        ActiveSheet.Cells(4, 2).Formula = Right(nom, Len(nom) - 5)
                        ActiveWorkbook.Save
                    End If
                End With
    Next
    End Sub
    Sub imprime()
    '
    For i = 1 To Selection.Count
    ligne = Selection.Cells(i, 1).Row
    nom = "prix_" + ActiveCell.Text + ".xls"
                With Application.FileSearch
                    .LookIn = ActiveWorkbook.Path
                    .Filename = nom
                    .MatchTextExactly = True
                If .Execute() = 1 Then
                    If .FoundFiles(1) = ActiveWorkbook.Path + "\" + nom Then
                    form = "='" + ActiveWorkbook.Path + "\[" + nom + "]prix_" + ActiveCell.Text + "'!$K$33"
                    Workbooks.Open Filename:=ActiveWorkbook.Path + "\" + nom
                    ActiveWorkbook.ActiveSheet.PrintOut
                    ActiveWorkbook.Saved = True
                    ActiveWorkbook.Close
                    End If
                End If
                End With
    Next
    End Sub

Discussions similaires

  1. Modification de Application.filesearch sous Excel 2007
    Par besastyle dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 07/11/2008, 13h24
  2. Lenteurs de macros VBA sous Excel 2007 vs Excel 2003
    Par nicotab dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 06/11/2007, 18h47
  3. Une fonction sous Excel 2007 ne fonctionne pas sous Excel 2003
    Par Dryss51 dans le forum Macros et VBA Excel
    Réponses: 14
    Dernier message: 27/07/2007, 08h09
  4. [VBA] VBA sous Excel 2007
    Par tangjuncn dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 28/02/2007, 16h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo