Identify Capital Paragraphs with VBA for word.

I

itsyash

Hi,

How can I identify a paragraph that has all word in captial letters in
Microsoft Word.

For example:

ROAD SAFETY SHOW

We had a road safety show and we were walking along the road. Suddenly
we started to dance and we got to know that a new ice cream shop has
opened up.

In the example above, I want to be able to identify "ROAD SAFETY SHOW"
and then have the text formatted as shown below.

#TITLE#ROAD SAFETY SHOW#/TITLE#

We had a road safety show and we were walking along the road. Suddenly
we started to dance and we got to know that a new ice cream shop has
opened up.


Can someone please help me with this?

Thanks,
Yash
 
D

Dave Lett

Hi,

You can use something like the following:

Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
With oPara.Range
If .Case = wdUpperCase Then
.Case = wdTitleWord
End If
End With
Next oPara

HTH,
Dave
 
I

itsyash

Hi Dave,

Thanks for your response. This looks great. I am a novice with Word
VBA. If you dont mind can you help me with the code to add #TITLE#
before the paragraph starts and #/TITLE# after the paragraph ends.

Also can you tell me if there is a way I can identify each line in a
word document.

Thanks in advance,
Yash
 
D

Dave Lett

Yes, I can, after all that was in your original post.

Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
With oPara.Range
If .Characters.Count > 1 Then
If .Case = wdUpperCase Then
.Case = wdTitleWord
.InsertBefore "#Title#"
.End = .End - 1
.InsertAfter "#/Title#"
End If
End If
End With
Next oPara

HTH,
Dave
 
I

itsyash

Hi Dave,

I tried this. I get an error message at the first line saying Compile
Error: User defined type not defined.

Thanks,
Yash
 
I

itsyash

Sorry. I was trying to paste it in Excel VBA

It works great. Awesome

Thanks buddy.
 

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