如何解决如何在 MS Word 中捕获段落标题和评论页码
我有这个 VB 代码,可以将 MS Word 中的评论和作者姓名提取到 Excel,如何捕获段落标题和评论的页码?我希望我的 excel 有作者姓名、评论、段落标题和页码。
这是我的代码
导入 Microsoft.Office
导入 Microsoft.Office.Interop
导入 Microsoft.Office.Interop.Word
公开课表1 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
结束课程
解决方法
例如,在 VBA 中:
Sheet.Range("D" & I).Value = cmt.Reference.Information(1) 'wdActiveEndAdjustedPageNumber
Sheet.Range("E" & I).Value = cmt.Reference.Bookmarks("\Headinglevel").Range.Paragraphs.First.Range.Text
我会让你来做 vb.net 等价物。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。