2017-05-03 3 views
0

Ich habe Probleme mit meinem AppleScript, das alle Dateinamen entfernt, die länger als 13 Zeichen sind. Ich habe eine Liste von Dateinamen in Spalte B und ich brauche nur diejenigen, die 13 Zeichen sind, nicht mehr als. Ich bin auf der Suche nach dem Skript, um die Zeile von etwas mehr als 13 zu löschen. Bisher hat das etwas funktioniert und nicht alle entfernt.AppleScript Zählen und Entfernen von Zeichen in Excel

 tell application "Microsoft Excel" 
     activate 
     open (choose file with prompt "Select the Excel file you wish to use.") 
    end tell 


    tell application "Microsoft Excel" 
     tell active sheet 
      autofit column "A:H" 
     end tell 
    end tell 

set cellNumber to 2 

    tell application "Microsoft Excel" 
     activate 
     repeat 
      set fileName to get value of cell ("B" & cellNumber) as string 
      set fncount to count characters of fileName 
      if fncount is greater than 13 then 
       delete entire row of cell ("B" & cellNumber) 
       set endCount to 0 
      else 
       set endCount to endCount + 1 
       if endCount > 100 then 
        exit repeat 
       end if 
      end if 
      set cellNumber to cellNumber + 1 
     end repeat 
    end tell 
    set endCount to 0 

Antwort

0

Dies alles nicht gelöscht werden, da, wenn das Skript eine Zeile löschen, Excel auf die Zeilen verschieben.

Beispiel: das Skript die zweite Zeile löschen, nun die zweite Reihe ist die dritte Reihe, so dass das Skript eine Reihe

springt Um zu vermeiden, muss die Schleife am Index starten der letzten Reihe.

Verwenden Sie die used range-Eigenschaft, um die letzte Zeile zu erhalten.

tell application "Microsoft Excel" 
    activate 
    open (choose file with prompt "Select the Excel file you wish to use.") 
    tell active sheet 
     set cellNumber to 2 
     autofit column "A:H" 
     set lastR to count rows of used range -- get the index of the last row which contains a value 
     repeat with i from lastR to cellNumber by -1 -- iterates backwards from the index of the last row 
      set fileName to string value of cell ("B" & i) 
      if (count fileName) > 13 then delete row i 
     end repeat 
    end tell 
end tell 
+0

Vielen Dank! Das hat den Trick gemacht! –

Verwandte Themen