Function FileRename(oldpathname As String, newpathname As String) As Byte FileRename = 0 'on verifi que le fichier source existe et que le nouveau nom n'est pas déjà utilisé If Not Dir(oldpathname) "" And Dir(newpathname) "" Then On Error Resume Next Name oldpathname As newpathname If Error = 0 Then FileRename = 1 Else 'si erreur FileRename = Err Err.Clear End If On Error GoTo 0 End If End Function
Sub test() Dim ReturnValue As Byte, AncienCheminNom As String, NouveauCheminNom As String Dim Msg As String AncienCheminNom = "C:\Temp\FichierTest.txt" NouveauCheminNom = "C:\Temp\NewFichierTest.txt" ReturnValue = FileRename(AncienCheminNom, NouveauCheminNom) If ReturnValue = 0 Then Msg = "Le fichier n'a pu être renommé !" & Chr(13) & Chr(13) & _ "Veuillez vérifier que: " & Chr(13) & Chr(13) & _ "Le fichier " & NouveauCheminNom & " existe !" & Chr(13) & _ "ou que le fichier " & NouveauCheminNom & " n'existe pas déjà ! " MsgBox Msg, vbExclamation, "Erreur" Elseif ReturnValue > 1 Msg = "L'erreur n° " & Str(Err.Number) & " a été générée par " _ & Err.Source & Chr(13) & Err.Description MsgBox Msg, , "Erreur", Err.HelpFile, Err.HelpContext End If End Sub
Set A = Fs.CreateTextFile(Sheets("kml").Range("A1").Text & ".txt", True)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionSub FICELLERTE() Dim Destination, MaPlage, PL, R, DEST As Range Dim Fs, U As Object Dim FIC, ErrMsg, mot, PA As String Dim K As Long Dim Result, Choices, DL As Integer Application.ScreenUpdating = False Application.DisplayAlerts = False Sheets("Work_Sheet_2").Select Cells.ClearContents Sheets("RTE_FLITESTAR").Select Cells.ClearContents Sheets("Compilation").Select Set Destination = Sheets("Work_Sheet_2").Range("A1") Set MaPlage = Sheets("Compilation").Range("A1:M" & Sheets("Compilation").Range("A65536").End(xlUp).Row) Set tbl = ActiveCell.CurrentRegion tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1, tbl.Columns.Count).Select MaPlage.Copy Destination With Sheets("Work_Sheet_2") Range("N1").FormulaR1C1 = "1" Cells.Find("*", after:=[A1], LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, searchdirection:=xlPrevious, _ MatchCase:=False, SearchFormat:=False).Select n = Selection.Row mot = InputBox("Donnez code OACI") DL = .Cells(Application.Rows.Count, 1).End(xlUp).Row Set PL = .Range("T1:T" & DL) Set R = PL.Find(mot, , xlValues, xlWhole) End With If Not R Is Nothing Then PA = R.adress With Sheets("RTE_FLITESTAR") Set DEST IIf(.Cells(1, 1) "", .Cells(1, 1), .Cells(Application.Rows.Count, 1).End(xlUp).Offset(1, 0)) End With With Sheets("Work_Sheet_2") If n > 299 Then MsgBox ("Dépassement de la capacité de traitement ROUTE (>300)") For compteur = 1 To PA .Range("T1:T" & compteur).Value.Copy DEST Next compteur End If End With For i = 1 To n Cells(i, 14).FormulaR1C1 = _ "=R[-1]C+1" Cells(i, 15).FormulaR1C1 = _ "=RC[-9]+((500*RC[-8]+3*RC[-7])/30000)" Cells(i, 17).FormulaR1C1 = _ "=RC[-7]+((500*RC[-6]+3*RC[-5])/30000)" Cells(i, 16).FormulaR1C1 = _ "=IF(RC[-11]=""s"",-RC[-1],RC[-1])" Cells(i, 18).FormulaR1C1 = _ "=IF(RC[-9]=""W"",-RC[-1],RC[-1])" Cells(i, 20).FormulaR1C1 = _ "=CONCATENATE(""W, 0, "",C[-6],"", "",C[-6],"","",C[-16],"" , "",C[-4],"", "",C[-2],"",39154.4176025, 111, 4, 5, 255, 13158342,0, 0, 0"")" Next i Range("T1:T65000").Copy Sheets("RTE_FLITESTAR").Columns("A:A").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False Sheets("RTE_FLITESTAR").Select For j = 1 To 5 Rows("1:1").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Next j Range("A1").FormulaR1C1 = "OziExplorer Route File Version 1.0" Range("A2").FormulaR1C1 = "WGS 84" Range("A3").FormulaR1C1 = "Reserved 1" Range("A4").FormulaR1C1 = "Reserved 2" Range("A5").FormulaR1C1 = "R, 0,R0 ,,255" Set Fs = CreateObject("Scripting.FileSystemObject") Set U = Fs.CreateTextFile("\\Etudes\public\03_MISSION\01_PREPARATION_MISSION\OUTIL ROUTE FLITESTAR\Route\RTE_FLITESTAR.rte", True) With Sheets("RTE_FLITESTAR") For K = 1 To .Cells(.Rows.Count, "A").End(xlUp).Row On Error GoTo Errorhandler U.WriteLine (.Range("A" & K).Value) Next K Errorhandler: Select Case Err.Number Case 13: ErrMsg = "Une erreur est survenue ligne " & K - 5 & " de la feuille Compilation." Result = MsgBox(ErrMsg, Choices) If Result = vbOK Then Resume Next End If End Select U.Close Set U = Nothing Set Fs = Nothing NOM = InputBox("Donnez un nom de fichier.wpt") If NOM = "" Then Exit Sub Else GoTo continu End If continu: FIC = Dir("\\Etudes\public\03_MISSION\01_PREPARATION_MISSION\OUTIL ROUTE FLITESTAR\Route\RTE_FLITESTAR.rte") If FIC <> "" Then Name "\\Etudes\public\03_MISSION\01_PREPARATION_MISSION\OUTIL ROUTE FLITESTAR\Route" _ & FIC As "\\Etudes\public\03_MISSION\01_PREPARATION_MISSION\OUTIL ROUTE FLITESTAR\Route" & NOM & ".rte" End With Sheets("Main_Sheet").Select Application.DisplayAlerts = True Application.ScreenUpdating = True MsgBox ("Export ROUTE réussi") End If End Sub