Ciao MaAn56,
Il tuo codice andrebbe riscritto per esempio così:
Dim vntFound As Variant
vntFound = MyFileSearch(FName1, Directory)
If IsEmpty(vntFound) Then
' Nessun file trovato.
Else
For i = 0 To UBound(vntFound)
Richiesta = MsgBox("Il File:" _
& " " & GetFilenameFromFullname(vntFound(i)) _
& " già Esiste" _
& vbCr & "Vuoi Creare un'altra Scheda ?" _
, vbYesNo)
If Richiesta = vbYes Then
GoTo 1
Else
GoTo 2
End If
Next
End If
se decidi di usare la seguente funzione che ho proposto in quel post e che dovrai
copiare e incollare in un Modulo standard:
Public Function MyFileSearch(Optional ByVal Filename As String _
, Optional ByVal Path As String)
Dim strPath As String
Dim strFilename As String
Dim strDir As String
Dim strFound() As String
If Len(Path) Then strPath = Path Else strPath = CurDir$
If Right$(strPath, 1) <> "" Then strPath = strPath & ""
If Len(Filename) Then strFilename = Filename Else strFilename = "*.*"
strDir = Dir(strPath & strFilename, vbNormal)
If Len(strDir) = 0 Then Exit Function
ReDim strFound(0)
Do While Len(strDir)
strFound(UBound(strFound)) = strPath & strDir
ReDim Preserve strFound(UBound(strFound) + 1)
strDir = Dir
Loop
ReDim Preserve strFound(UBound(strFound) - 1)
MyFileSearch = strFound
End Function
Insieme alla seguente, che estrae Nome e Estensione del nome del file dal Percorso completo restituito dalla funzione 'MyFileSearch':
Public Function GetFilenameFromFullname(ByVal Fullname As String) As String
On Error Resume Next
GetFilenameFromFullname = Mid$(Fullname _
, InStrRev(Fullname _
, "" _
, Compare:=vbTextCompare) + 1)
End Function
Ovviamente si può sofisticare di più il tutto, in caso di bisogno, ma a quanto vedo da quel che scrivi dovrebbe bastare così.