2010-04-29 64 views
4

我正試圖導出Word文檔的評論評論。我想導出評論後的評論句子選擇。圖像的導出Word評論評論時,您如何參考與評論相關的句子?

屏幕截圖:http://jspeaks.com/mswordcomment.png

我已經通過文件註釋中發現的代碼迴路,但我無法弄清楚如何引用有人評論相關句子的選擇。

當前的邏輯是:

Sub ExportComments() 
    Dim s As String 
    Dim cmt As Word.Comment 
    Dim doc As Word.Document 

    For Each cmt In ActiveDocument.Comments 
     s = s & cmt.Initial & cmt.Index & "," & cmt.Range.Text & vbCr 
    Next 

    Set doc = Documents.Add 
    doc.Range.Text = s 
End Sub 

我與Selection.Range修修補補,但是我不能確定包含被引用的句子正確的對象或屬性。

我想產生這樣(如果我們使用的例子在上面圖片)輸出:

一句話:這裏是包含有趣的事實更多的句子 - 簡評:這是一個有趣的事實。 句子:這裏有更多的句子包含有趣的事實。這裏有更多包含有趣事實的句子。 - 評論:這是一個非常有趣的事實

回答

8

我發現有人在另一個網站上解決這個問題。

到解決問題的關鍵是:cmt.Scope.FormattedText

下面是修改後的功能:

Sub ExportComments() 
    Dim s As String 
    Dim cmt As Word.Comment 
    Dim doc As Word.Document 

    For Each cmt In ActiveDocument.Comments 
     s = s & "Text: " & cmt.Scope.FormattedText & " -> " 
     s = s & "Comments: " & cmt.Initial & cmt.Index & ":" & cmt.Range.Text & vbCr 
    Next 

    Set doc = Documents.Add 
    doc.Range.Text = s 
End Sub 
+2

很好,你有一個解決方案。你可以繼續,並接受你自己的答案作爲正確答案(複選標記)。 – 2010-06-27 15:49:32

3

我已經收集幾件代碼,並來到這個解決方案:

Sub CopyCommentsToExcel() 
'Create in Word vba 
'TODO: set a reference to the Excel object library (Tools --> Reference --> Microsoft Excel 12.0 Object library) 

Dim xlApp As Excel.Application 
Dim xlWB As Excel.Workbook 
Dim i As Integer 
Dim HeadingRow As Integer 
HeadingRow = 3 

Dim cmtRef As Range 

Set xlApp = CreateObject("Excel.Application") 
xlApp.Visible = True 
Set xlWB = xlApp.Workbooks.Add ' create a new workbook 
With xlWB.Worksheets(1) 
' Create report info 
    .Cells(1, 1).Formula = "Reviewed document:" 

' Create Heading 
    .Cells(HeadingRow, 1).Formula = "Index" 
    .Cells(HeadingRow, 2).Formula = "Page" 
    .Cells(HeadingRow, 3).Formula = "Line" 
    .Cells(HeadingRow, 4).Formula = "Comment" 
    .Cells(HeadingRow, 5).Formula = "Reviewer" 
    .Cells(HeadingRow, 6).Formula = "Date" 
    For i = 1 To ActiveDocument.Comments.Count 
     .Cells(2, 1).Formula = ActiveDocument.Comments(i).Parent 
     .Cells(i + HeadingRow, 1).Formula = ActiveDocument.Comments(i).Index 
     .Cells(i + HeadingRow, 2).Formula = ActiveDocument.Comments(i).Reference.Information(wdActiveEndAdjustedPageNumber) 
     .Cells(i + HeadingRow, 3).Formula = ActiveDocument.Comments(i).Reference.Information(wdFirstCharacterLineNumber) 
     .Cells(i + HeadingRow, 4).Formula = ActiveDocument.Comments(i).Range 
     .Cells(i + HeadingRow, 5).Formula = ActiveDocument.Comments(i).Initial 
     .Cells(i + HeadingRow, 6).Formula = Format(ActiveDocument.Comments(i).Date, "dd/MM/yyyy") 
     '  .Cells(i + 1, 3).Formula = ActiveDocument.Comments(i).Parent 
     '  .Cells(i + 1, 3).Formula = ActiveDocument.Comments(i).Application 
     '  .Cells(i + 1, 7).Formula = ActiveDocument.Comments(i).Author 
    Next i 
End With 
Set xlWB = Nothing 
Set xlApp = Nothing 
End Sub 

最有價值的幫助Microsoft Answers

+0

user662182: 感謝您的出色貢獻,但是此宏不會在Word 2007下編譯,直到用戶 按照VBA源代碼的TODO註釋中的說明操作。 重要的是要注意,如果用戶沒有這樣做,工具 - >引用選項將灰顯出來......重置VB編輯器中的當前宏,那麼該選項是活動的! – user2831074 2014-12-17 14:44:09