Select text but not tables

N

New to VBA

I have this Word document macro that, if there are comments in the text,
selects all the text and changes the font to 14 points:

With ActiveDocument.Range
If .Comments.Count > 0 Then
.Font.Name = "Times New Roman"
.Font.Size = 14
End If

However, if there are tables in the document with a smaller font, the font
change to 14 points
creates havoc with the table format.

Is there a way to select only the text and change the font size but leave
the tables unchanged?

Thaks in advance,
 
J

Jezebel

Your macro doesn't select any text; it just changes the entire document to
14pt TNR if there is a comment in the document. What are you actually trying
to do?
 
M

macropod

Hi,

Try testing whether the range is in a table, and only acting otherwise. For
example:

Sub BigCommentedText()
Dim oComment
Dim oRange
If ActiveDocument.Comments.Count > 0 Then
For Each oComment In ActiveDocument.Comments
Set oRange = oComment.Scope
oRange.Select
If Not Selection.Information(wdWithInTable) Then
With oRange.Paragraphs(1).Range
.Font.Name = "Times New Roman"
.Font.Size = 14
End With
End If
Next oComment
End If
End Sub

Cheers
 
N

New to VBA

X-No-Archive
14pt TNR if there is a comment in the document. What are you actually trying
to do?<<

Maybe I didn't express myself clearly; yes, the code changes the entire
document to 14pt if there is a comment in the document. What I am trying to
do is find a
way to change everything in the document to 14pt but NOT the tables.

Thanks in advance.
 
N

New to VBA

X-No-Archive

Thanks a lot for your code, it works flawlessly but unfortunately only
changes the paragraphs with comments, not all the pargraphs, including those
without comments, but NOT the tables, which is what I am trying to do.

Regards,
 
J

Jezebel

If your tables have a standard size, simplest would be to change the entire
document, then change the tables back to what you want. Failing, that,
iterate the paragraphs and change them if they are not within a table --

Dim pPar as Word.Paragraph
For each pPar in ActiveDocument.Paragraphs
if not pPar.Range.Information(wdWithInTable) then
with pPar.Range.Name
.Size = 14
.Name = "Times ...
end with
end if
Next





Or, better if the document is well-structured using styles (one set for body
text, another for tables), change the size of the body text style to 14.
 
M

macropod

Hi,

From looking at your code and your original problem description, that's what
I thought you were trying to do.

If your trying to change the non-table text in documents that have comments
attached, try this instead:
Sub BigText()
Dim i As Integer
With ActiveDocument
If .Comments.Count = 0 Then Exit Sub
For i = 1 To .Paragraphs.Count
If Not .Paragraphs(i).Range.Information(wdWithInTable) Then
With .Paragraphs(i).Range
.Font.Name = "Times New Roman"
.Font.Size = 14
End With
End If
Next i
End With
End Sub

If the existence of comments is irrelevant, comment out or delete the line:
If .Comments.Count = 0 Then Exit Sub

Cheers
 
N

New to VBA

X-No-Archive

Thank you both! Your code and macropod's worked perfectly.

Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top