2016-08-24 4 views
0

현재 텍스트 파일 (c : \ temp \ temp.txt)이 있는데 VBA를 사용하여 파일을 편집하고 문자열 데이터의 세 번째 행을 지울 수 있기를 원합니다. (그래서 변수가 무엇인지 말할 수는 없지만) 나머지 텍스트 행은 그대로 유지하십시오.VBA 텍스트 파일의 세 번째 줄 편집

나는 파일을 열어서 전체 파일을 문자열로 저장 한 다음 파일을 닫았다가 다시 열고 문자열을 편집하고 저장해야하는 것처럼 보였습니다.

도움이 될 것입니다.

+0

를 사용할 수있는 비트 과잉 버전 : 개인적으로 줄 바꿈에 분할하고 다시 각각의 라인을 써서 - 파일을 읽고 (http://stackoverflow.com/documentation/vba/990/scripting-filesystemobject/3221/reading-a-text-file-using-a-filesystemobject#t=201608242132490774474) 파일을 작성합니다 (http : //stackoverflow.com/documentation/vba/990/scripting-filesystemobject/3223/writing-to-an-existing-file-with-filesystemobject#t=201608242132490774474) – Mikegrann

답변

4

의사 코드는 사용자가해야 할 일입니다. 당신이 경우에, 우리의 VBA의 문서를 살펴

Private Sub KillLineThree(filepath As String) 
    With CreateObject("Scripting.FileSystemObject") 
     Dim lines() As String 
     With .OpenTextFile(filepath) 
      lines = Split(.ReadAll, vbCrLf) 
      .Close 
     End With 

     Dim i As Long 
     With .CreateTextFile(filepath) 
      For i = LBound(lines) To UBound(lines) 
       If i <> 2 Then .WriteLine lines(i) 
      Next 
      .Close 
     End With 
    End With 
End Sub 
+0

이것은 완벽한 감사입니다! – Snoobie

1

을 짧은 당신이 엑셀

Workbooks.Open "c:\temp\temp.txt" 
Rows(3).Delete 
DisplayAlerts = False 
ActiveWorkbook.Close True 
DisplayAlerts = True 
+0

창조적 인 해결책! 나는 그것을 좋아한다! – Snoobie

관련 문제