":"문자가있는 행이 있으면 txt 파일 내부에서 찾기 위해 Microsoft Word에서 VBA 스크립트를 만들려고합니다. 이것이 사실이라면, 나는이 줄을 쪼개서이 정보를 주 파일에있는 테이블에 삽입하고 싶다. 이 objetive 위해, 나는이 정보를 얻으려면 모두 라인을 통해 가고 싶습니다.내 워드 매크로에서 두 번째 단어를 찾지 못했습니다.
[email protected]
[email protected]
[email protected]:word1:word2
[email protected]
[email protected]:word3:word4
포함하는 첫 번째 줄 ":"3 호선을 Mails.txt에
Dim arrNames
Dim cont As Integer
cont = 0
strPath = ActiveDocument.name
Documents.Open path & "Mails.txt"
strPath2 = ActiveDocument.name
With Selection.Find
.Text = ":"
Do While .Execute(Forward:=True, Format:=True) = True
Selection.Find.Execute FindText:=(":")
Selection.Expand wdLine
arrNames = Split(Selection.Text, ":")
Documents(strPath).Activate
If cont = 0 Then
Call gestOSINT("Pwd")
Selection.Find.Execute FindText:=("[Pwd]")
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "Tabla con cuadrícula" Then
.Style = "Tabla con cuadrícula"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
End With
Set tblNew = Selection.Tables(1)
tblNew.Style = "Tabla de lista 1 clara - Énfasis 1"
Selection.TypeText Text:="Correo electrónico"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Tipo de filtrado"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Plataforma"
End If
Set rowNew = tblNew.Rows.Add
rowNew.Cells(1).Range.Text = arrNames(0)
rowNew.Cells(2).Range.Text = arrNames(1)
rowNew.Cells(3).Range.Text = arrNames(2)
cont = cont + 1
Documents(strPath2).Activate
Selection.Text = arrNames(0) & vbCrLf
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Collapse wdCollapseEnd
Loop
End With
Documents(strPath2).Activate
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Documents(strPath).Activate
If cont = 0 Then
pwdMails = False
Else
pwdMails = True
End If
그리고 Mails.txt 파일은 다음을 포함 :이를 위해
,이 코드가 , 찾을 수 있지만 두 번째 줄, Mails.txt 5 번째 줄을 찾을 수 없습니다.
왜 이런 현상이 발생합니까? 어떻게 해결할 수 있습니까?
당신은'사용 Selection''와 Find', 항상'Selection.Collapse wdCollapseEnd'를 추가, 다른 말씀은 이제 하나 개의 라인으로 구성만을 선택에서 검색합니다 ... 또한 :이 파일은 텍스트 파일이므로 FileSystemObject 사용을 고려하십시오. https://stackoverflow.com/questions/1719342/how-to-read-lines-from-a-text-file-one-by-one- with-power-point-vba-code – LocEngineer