I have this VB code that extracts comment and Author name from MS Word to Excel, How do I capture Paragraph heading and Page number of comment? I want my excel to have Author name, Comment, paragraph heading and page number.
Here's my code
Imports Microsoft.Office
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Word
Public Class Form1
Dim fileName As String = "None"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If fileName = "None" Then
MsgBox("Please select a file", vbExclamation, "Info")
Return
End If
Dim oWord As Object ' Word.Application
Dim oDoc As Object ' Word.Document
oWord = CreateObject("Word.Application")
oWord.Visible = False
oWord.Documents.Open(fileName)
oWord.Visible = False
Dim ExcelApp = CreateObject("Excel.Application")
Dim WorkBooks = ExcelApp.Workbooks
Dim Book = WorkBooks.Add
Dim Sheets = Book.Sheets
Dim Sheet = Sheets(1)
Sheet.Range("A1").Value = "Comment"
Sheet.Range("B1").Value = "Author"
Sheet.Range("C1").Value = "Date"
Sheet.Columns("A").ColumnWidth = 50
Sheet.Columns("B").ColumnWidth = 30
Sheet.Columns("C").ColumnWidth = 30
Dim I As Integer = 1
For Each oDoc In oWord.Documents
For Each cmt In oDoc.Comments
I += 1
Sheet.Range("A" & I).Value = cmt.Range.Text
Sheet.Range("B" & I).Value = cmt.Author
Sheet.Range("C" & I).Value = cmt.Comments().Date
Next
Next
ExcelApp.Visible = True
Me.WindowState = System.Windows.Forms.FormWindowState.Minimized
End Sub
Private Sub btnSelect_Click(sender As Object, e As EventArgs) Handles btnSelect.Click
Dim OFD As New OpenFileDialog()
OFD.Title = "Select your Word file"
' OFD.Filter = "Word Files (*.txt)|*.txt"
If OFD.ShowDialog() <> DialogResult.Cancel Then
fileName = OFD.FileName
If Len(fileName) > 27 Then
lblSelectedFile.Text = Strings.Left(fileName, 7) & " ... " & Strings.Right(fileName, 13)
Else
lblSelectedFile.Text = fileName
End If
Else
Return
End If
End Sub
Private Sub lblSelectedFile_Click(sender As Object, e As EventArgs) Handles lblSelectedFile.Click
End Sub
End Class
question from:
https://stackoverflow.com/questions/66059312/how-to-capture-paragraph-heading-and-page-number-of-comment-in-ms-word 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…