Recherche string

Bonjour,

comment je peux chercher un string qui commence par une variable que je connais, je m'explique :

Dim A as string
Dim B as string

A= textbox1.value
B= (A & "*")

Merci d'avance

Bonjour,

Un tantinet plus de détails serait bienvenu ! Tu veux chercher où ? Dans une colonne spécifique de ta feuille ?

Aurais-tu un fichier à transmettre pour illustrer tout ça ?

Je cherche un dossier, le nom du dossier doit commencer par ma variable A, peut importe la suite du nom du dossier ce qui m'interesse c'est que ca commence par la variable A.

voici le code :

Option Explicit
Dim FileSystem As Object
Dim HostFolder As String

Sub FindFile()
HostFolder = "S:\1 - Projet BE"

Set FileSystem = CreateObject("Scripting.FileSystemObject")
DoFolder FileSystem.GetFolder(HostFolder)

End Sub
Sub DoFolder(Folder)
Dim a As String
a = "123"
    Dim SubFolder
    For Each SubFolder In Folder.SubFolders
        DoFolder SubFolder
    Next
    Dim File
    For Each File In Folder.Files
        If File.Name = (a & "*") Then
           MsgBox (File.Path)

            Exit Sub
        End If
    Next
End Sub

Merci d'avance

UP

pouvez vous m'aider svp !

bonjour,

j'ai resolu le probleme autrement.

je l'aisse à l'utilisateur de choisir le dossier ou mettre son fichier a deplacer :

la fonction :

'Fonction pour selectionner le dossier du projet ou deplacer la piece de gabarit standard

Function BrowseForFolder(Optional OpenAt As Variant) As Variant
     'Function purpose:  To Browser for a user selected folder.
     'If the "OpenAt" path is provided, open the browser at that directory
     'NOTE:  If invalid, it will open at the Desktop level

    Dim ShellApp As Object

     'Create a file browser window at the default folder
    Set ShellApp = CreateObject("Shell.Application"). _
    BrowseForFolder(0, "Please choose a folder", 0, OpenAt)

     'Set the folder to that selected.  (On error in case cancelled)
    On Error Resume Next
    BrowseForFolder = ShellApp.self.Path
    On Error GoTo 0

     'Destroy the Shell Application
    Set ShellApp = Nothing

     'Check for invalid or non-entries and send to the Invalid error
     'handler if found
     'Valid selections can begin L: (where L is a letter) or
     '\\ (as in \\servername\sharename.  All others are invalid
    Select Case Mid(BrowseForFolder, 2, 1)
    Case Is = ":"
        If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
    Case Is = "\"
        If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
    Case Else
        GoTo Invalid
    End Select

    lien_destination = BrowseForFolder

    Exit Function

Invalid:
     'If it was determined that the selection was invalid, set to False
    BrowseForFolder = False
End Function

Dans le sub :

        'redirection vers "Annexe recherche dossier du projet pour deplacer le fichier du workspece"
        ofolder = BrowseForFolder("S:\National\Bureau d'études\2 - Base CAO\1 - Projet BE")

hors sub et function :

Public lien_destination As String

mais je suis toujours interessé par la solution du probleme initial

merci d'avance.

bonjour,

remplace cette instruction

If File.Name = (a & "*") Then

par celle-ci

If File.Name Like (a & "*") Then

tu peux aussi enlever les parenthèses qui ne sont pas utiles dans ce cas-ci.

tu es le meilleur

ca marche ... grand merciii

Rechercher des sujets similaires à "recherche string"