카테고리 없음
[VBA] 워드에서 특정 사용자 메모만 txt로 추출하기
Ufungi
2025. 6. 19. 16:17
Sub ExportCommentsByAuthorToTxt()
Dim cmt As Comment
Dim txtFile As String
Dim fileNum As Integer
Dim targetAuthor As String
targetAuthor = "홍길동" ' 원하는 작성자 이름 입력
txtFile = ThisDocument.Path & "\Comments_" & targetAuthor & ".txt"
fileNum = FreeFile
Open txtFile For Output As #fileNum
For Each cmt In ActiveDocument.Comments
If cmt.Author = targetAuthor Then
Print #fileNum, "Author: " & cmt.Author
Print #fileNum, "Date: " & cmt.Date
Print #fileNum, "Range: " & cmt.Scope.Text
Print #fileNum, "Comment: " & cmt.Range.Text
Print #fileNum, String(50, "-")
End If
Next cmt
Close #fileNum
MsgBox targetAuthor & "의 메모를 " & txtFile & "에 저장했습니다.", vbInformation
End Sub
- 워드에서 Alt + F11 눌러 VBA 편집기 열기
- 삽입 > 모듈 선택 후 위 코드를 붙여넣기
- F5 눌러 실행하면, 현재 문서와 같은 폴더에 Comments.txt 파일로 메모가 저장됨