Function GetLastIndex(ByVal directory As String, ByVal Title As String) Const EXT_SLDPRT As String = ".sldprt" Dim file As String Dim indexPos As Long Dim index As Long Dim maxIndex As Long If Not VBA.Right$(directory, 1) "" Then directory directory & "" maxIndex = 0 file = Dir(directory & Title & " -*" & EXT_SLDPRT, VbFileAttribute.vbNormal) While Not file = vbNullString indexPos = VBA.InStrRev(file, "-") If indexPos > 0 Then index = Int(Val(VBA.Trim$(VBA.Mid$(file, indexPos + 1, Len(file) - indexPos - Len(EXT_SLDPRT))))) If index > maxIndex Then maxIndex = index End If file = Dir() Wend GetLastIndex = maxIndex End Function
index = GetLastIndex(MyFolder, Strings.Mid(swModel.GetTitle, 1, 11)) + 1
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questiontu souleves une autre alternative l'ecriture de tous les noms de fichiers dans un fichiers textes ....
Function GetLastIndex(ByVal directory As String) Const EXT_SLDPRT As String = ".sldprt" Dim file As String Dim indexPos As Long Dim index As Long Dim maxIndex As Long If Not VBA.Right$(directory, 1) "" Then directory directory & "" maxIndex = 0 file = Dir(directory & "*" & EXT_SLDPRT, VbFileAttribute.vbNormal) While Not file = vbNullString indexPos = VBA.InStrRev(file, "-") If indexPos > 0 Then index = Int(Val(VBA.Trim$(VBA.Mid$(file, indexPos + 1, Len(file) - indexPos - Len(EXT_SLDPRT))))) If index > maxIndex Then maxIndex = index End If file = Dir() Wend GetLastIndex = maxIndex End Function
RAPPEL ... un débutant en VBA est un million de fois plus fort que moi
MyFolder = Strings.Left(swModel.GetPathName, Strings.InStrRev(swModel.GetPathName, "") - 1) + "" index = GetLastIndex(MyFolder) + 1 ' <---- ICI --------------- FileName = Strings.Mid(swModel.GetTitle, 1, 11) + " - " FileName = MyFolder & FileName & FichierActif & " - " & index & ".sldprt"
je ne vois pas quelle description du cahier des charges de cette macro te manque ... attendu que certains arrivent à proposer des solutions ...