gpt4 book ai didi

excel - 从 Word 中提取作者和评论到 Excel

转载 作者:行者123 更新时间:2023-12-04 20:55:04 28 4
gpt4 key购买 nike

我有以下代码,它从 Word 文档中提取文本字符串并将其导出到 Excel 电子表格中。 A 列读取注释,B 列读取它所引用的原始文本。我还想提取在电子表格中发表评论但不知道如何提取的作者。谢谢。

    Option Explicit




Public Sub FindWordComments()
'Requires reference to Microsoft Word v14.0 Object Library

Dim objExcelApp As Object
Dim wb As Object
Set objExcelApp = CreateObject("Excel.Application")
Set wb = objExcelApp.Workbooks.Open("C:\Users\cetraig\Documents\Projects\_HRBT\Book1.xlsx")

Dim myWord As Word.Application
Dim myDoc As Word.Document
Dim thisComment As Word.Comment

Dim fDialog As Office.FileDialog
Dim varFile As Variant

Dim destSheet As Worksheet
Dim rowToUse As Integer
Dim colToUse As Long

Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
Set destSheet = wb.Sheets("Sheet1")
colToUse = 1

With fDialog
.AllowMultiSelect = True
.Title = "Import Files"
.Filters.Clear
.Filters.Add "Word Documents", "*.docx"
.Filters.Add "Word Macro Documents", "*.docm"
.Filters.Add "All Files", "*.*"
End With

If fDialog.Show Then

For Each varFile In fDialog.SelectedItems

rowToUse = 2

Set myWord = New Word.Application
Set myDoc = myWord.Documents.Open(varFile)

For Each thisComment In myDoc.Comments

With thisComment
destSheet.Cells(rowToUse, colToUse).Value = .Range.Text
destSheet.Cells(rowToUse, colToUse + 1).Value = .Scope.Text
destSheet.Columns(2).AutoFit
End With

rowToUse = rowToUse + 1

Next thisComment

destSheet.Cells(1, colToUse).Value = Left(myDoc.Name, 4)
'Put name of interview object in cell A1

destSheet.Cells(1, colToUse + 1).Value = ActiveDocument.Words.Count
'Put the number of words in cell B1

Set myDoc = Nothing
myWord.Quit

colToUse = colToUse + 2

Next varFile

End If

End Sub

最佳答案

添加一行:

destSheet.Cells(rowToUse, colToUse + 2).Value = .Author

应该做的伎俩

(假设您希望它在下一列结束)

关于excel - 从 Word 中提取作者和评论到 Excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49803103/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com