Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word: Add Comment without "Comment"?

Status
Not open for further replies.

DrSimon

IS-IT--Management
Dec 14, 2001
674
GB
I have written code which goes though a document checking that the right font etc. has been used. When it finds an error, it calls the Sub below:
Code:
Private Sub Add_Comment(ByRef CommentRange As Range,   CommentStr As String)
    CommentRange.Select
    Selection.Comments.Add Range:=Selection.Range
    Selection.Comments(1).Initial = ""
    Selection.TypeText Text:=CommentStr
End Sub
Setting Initial ="" works fine but it still leaves the word "Comment" in the comment box as in :

[blue]Comment[1]:Incorrect Font Size (9)[/blue]

As there may be quite a lot of Comment boxes, the less I have in them the better. Does anyone know how I can remove the word "Comment" which seems to be a mandatory prefix?

Thanks
 


I can't give you THE Word VBA solution, since I'm one my way out the door, but in Excel, AFTER the comment is added, you can EDIT...
Code:
   With ActiveSheet.Comments(ActiveSheet.Comments.Count).Shape.OLEFormat.Object
        .Caption = Right(.Caption, Len(.Caption) - 11)
   End With
You ought to be able to figure something out with Word VBA, using the same technique.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
What about this ?
Code:
Private Sub Add_Comment(ByRef CommentRange As Range, CommentStr As String)
With ActiveDocument.Comments.Add(CommentRange, CommentStr)
    .Initial = ""
End With
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for trying guys.
Skip - very impressive while you're going out the door, but I can't see those objects for Comment in Word. Good to know that it's Caption I'm looking for.
PH - neater code, but I've already set Initial to "", that doesn't get rid of "Comment" though
 
I do not think this is possible.

Word Comments do not have a Caption. They are different beasties from Excel Cooments. Excel Comments are Shapes, and thus are part of the Shapes Collection.

Word Comments are in their own Story. Essentially on an independent object layer, Comments are part of the Comments Collection.

.Initial has nothing to do with initial text. It is the initials of the Author.

I am curious. How are you Calling this procedure? Is CommentRange passed as the current Selection?


unknown
 
Thanks Fumei. I couldn't find it anywhere but was intrigued to see if it could be done as the comments do get rather crammed and the less in the 'box' the better.

How am I calling this procedure? Basically I go through the Paragraphs in the Activedocument selecting as I go. I then do a format check and if the format is wrong I call this sub, if it's 'mixed' I go through all the Words in the Paragraph checking each one in the same way.

Is there a better way?

As an aside I use the Author property to give these a unique identifier so I can easily sweep though the Comments in the document and delete them.
 
If you know that something is "wrong" then you must also know what is "right".

So why don't you just fix it instead of making a comment?

And you should be using Styles instead of trying to automate the application of manual formatting.
 
Thanks for your feedback. These are documents compiled with inputs from a variety of people and as much as it would make sense to use styles, copying and pasting will go on. There are also numerous tables with different column formats that need to be catered for.

I know that I can 'fix' a number of the of the the errors, but the authors currently don't like their documents to be changed.
 
Those darn authors! Pain in the butt.

If these are comments regarding manual formatting, then yikes, I am with mintjulep on this. Styles are the way to use Word.

And, if you have so many Comments that the real estate they are using on screen is a problem, then you got much more of a problem that the Comments themselves.
How am I calling this procedure? Basically I go through the Paragraphs in the Activedocument selecting as I go. I then do a format check and if the format is wrong I call this sub, if it's 'mixed' I go through all the Words in the Paragraph checking each one in the same way.
Good heavens! That is awful. Ack! You have to go through and manually select each paragraph?


Ummmmm. Seems inordinately clumsy. Can you work out some sort of logic to at least help a bit? At least so you could select clumps of paragraphs?
Code:
Dim oPara As Paragraph

For Each oPara in Selection.Paragraph
   If oPara.Style = "MainText" And _
         oPara.Font.Size <> 12 Then
      oPara.Font.Size = 12
   End If
Next
So, say your MainText style has a font size of 12, if someone manually change the font size to something else, the code above would change it back, for every paragraph in the current Selection.

The point being is that any given Paragraph can still be style "Yadda" or "MainText" and have an incorrect explicit attribute, if that attribute ahs been manually changed.

I guess what I am suggesting is that IF there is some proper use of styles, you can do some logical determination of paragraph (or even words) matching to that style.

And if you can figure out the logic, you can probably code it.


unknown
 
Yeah - I can see how to correct the errors, but at this stage the authors are wary of this. So I need to point out the errors of their ways and I agree it's awful. The reason for the select is that the comment points to the errors concerned.
I now feel that I ought to push for the full solution rather than the warning!
Thanks.
 
Hi Guys - it was fun working out how to do this and it will be useful for some other stuff I'm doing, but I've taken your advice to heart. I've got a routine which does the changes but with mutiple options including creating a temporary copy, turning on tracking, updating fields etc. So I've got the best of both worlds - tracking identifies changes for free and the author has the option to delete changes.

Thanks
Simon

 
Hi DrSimon,

Rather than looping through all the paragraphs and testing their attributes against the underlying Styles, it would probably be more effieicient to loop through the Styles collection and use the Find function to locate all ranges using each Style. That way, you'll only need to obtain each Style's attributes once. It's also far more efficient when multiple consecutive paragraphs have the same Style, since the whole range can be tested as a block.

As for:
I then do a format check and if the format is wrong I call this sub, if it's 'mixed' I go through all the Words in the Paragraph checking each one in the same way.
this suggests the possibility of character Styles being used, or at least being an option. Something to consider.


Cheers
[MS MVP - Word]
 
macropod said:
it would probably be more effieicient to loop through the Styles collection and use the Find function to locate all ranges using each Style. That way, you'll only need to obtain each Style's attributes once.
Indeed it would. An excellent suggestion.


unknown
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top