VBA를 사용하여 Word 문서를 구문 분석하여 내용을 배열에 넣을 수있는 방법을 찾으려고합니다. 이 예제에서는 Word 문서에 두 개의 회사가 있으며 (코드 아래에 표시) 필드를 배열에 넣으려고합니다. 스택 오버플로 잘라 붙여VBA Excel - Word 문서의 구분 및 구문 분석 섹션에서 Excel에 데이터를 입력하십시오.
Public Sub ParseCompanies()
Dim Company_Array(1 To 2) As String 'stores individual company fields
Dim Companies_Array() 'array for all companies
Dim oWord As Object, oDoc As Object
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Open("C:/Temp/test.docx", Visible:=True)
Dim singleLine
Dim lineText As String
'need to rewrite this section
For Each singleLine In oDoc.Paragraphs
lineText = singleLine.Range.Text
Debug.Print lineText
Next singleLine
End Sub
Word 파일 내용 :
회사 : 알라딘 카펫
제품 : 매직 카펫
회사 : 안테나 조개
제품 : 조개
현재 스크립트가이 작업을 수행 할 수있는 효율적인 방법이 있나요 VBA를 디버거 출력
아래에서 볼 수 있습니다 실행하는 방법은? 개개의 회사를 파싱하기 위해 word 문서의 라인이나 섹션 스플리터를 구분하는 방법?