Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-14-2021, 06:31 AM
jimmy12 jimmy12 is offline Macro to maintain formatting OR to delete all text (excluding comments) Windows 10 Macro to maintain formatting OR to delete all text (excluding comments) Office 2016
Novice
Macro to maintain formatting OR to delete all text (excluding comments)
 
Join Date: May 2021
Posts: 4
jimmy12 is on a distinguished road
Question Macro to maintain formatting OR to delete all text (excluding comments)

Hi,



I have been using a Macro for some time that extracts all text in a Word that had been covered/highlighted by a comment, and inserts it into a new, separate Word document. However, the only issue is that the extracted text does not maintain the existing formatting of the original document, i.e. same font, same font size etc.. I'm not quite sure how best to edit my Macro for that function?

Code:
Sub AnalyseComments()
Dim oDoc As Document
Dim oNewDoc As Document
Dim oTable As Table
Dim nCount As Long
Dim n As Long

Set oDoc = ActiveDocument
nCount = ActiveDocument.Comments.Count

'Create a new document for the comments
Set oNewDoc = Documents.Add
'Insert a 4-column table for the comments
With oNewDoc
  .Content = ""
  Set oTable = .Tables.Add _
    (Range:=Selection.Range, _
    numrows:=nCount + 1, _
    NumColumns:=4)
End With

With oTable.Rows(1)
  .Range.Font.Bold = True
  .Cells(1).Range.Text = "Page"
  .Cells(2).Range.Text = "Comment scope"
  .Cells(3).Range.Text = "Comment text"
  .Cells(4).Range.Text = "Author"
End With
 
'Get info from each comment from oDoc and insert in table
For n = 1 To nCount
  With oTable.Rows(n + 1)
    'Page number
    .Cells(1).Range.Text = _
      oDoc.Comments(n).Scope.Information(wdActiveEndPageNumber)
    'The text marked by the comment
    .Cells(2).Range.Text = oDoc.Comments(n).Scope
    'The comment itself
    .Cells(3).Range.Text = oDoc.Comments(n).Range.Text
    'The comment author
    .Cells(4).Range.Text = oDoc.Comments(n).Author
  End With
Next n

oNewDoc.Activate
MsgBox "Finished creating comments document."
 
Set oDoc = Nothing
Set oNewDoc = Nothing
Set oTable = Nothing

End Sub
Alternatively, I thought about another Macro that would delete all text in the original document, but specifically excluding any text that had been covered/highlighted by a comment. This would therefore create a document with just the commented text and maintain the formatting. However, I'm a bit of a loss of creating this code.

I'd be grateful for any advice if anyone is able to help.

Last edited by macropod; 05-14-2021 at 09:11 PM. Reason: Added code tags & formatting
Reply With Quote
 

Tags
macro, vba, word macro



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA macro to change author name in tagged comments, then delete the tags mjt Word VBA 0 01-28-2021 08:48 AM
Macro to highlight and bolden specific text in Word Comments PCUSER Word VBA 1 09-22-2020 03:08 PM
Macro to maintain formatting OR to delete all text (excluding comments) Formula to delete but maintain counts after the maximum has been reached wheddingsjr Excel 2 01-03-2018 01:49 PM
Form won't maintain formatting SBrant Word 0 02-10-2011 10:29 AM
Macro to maintain formatting OR to delete all text (excluding comments) Maintain formatting while copying text from word, and pasting into a webpage. kdogg121 Word 1 07-07-2009 02:50 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft