All caps to Proper caps

J

Josha

Hi

I need to create a macro that will start at the begining of a Word document
and select all sections of text that are in ALLCAPS. It then must change the
instances of all caps to title or proper caps. However there are specific two
letter codes that must remain as all caps. Is this possible?

Basically, a mail merge that uses a database query as the datasource is
importing address and name details in allcaps. To maintain professionalism,
it is desired that these items are in proper caps. However, the letter
contains two letter 'class codes' that must remain in all caps (eg. BI, FH,
LF, NM).

I am only just learning VB and can only get the macro the select the whole
document and change it to proper caps. Manually selecting the required text
is not an option because the merge contains many records. This would take too
long.

My other thought was to use a macro to select specific line/column reference
to select the required text, then change it to proper caps, then repeat for
each page. I dont know how to do this either and it is not ideal as the
template letter may change, invalidating the references.

Any help would be much appreciated. I am *very* new to VB, so sample code
would be great.

Josha

--------------------------------------------------------------------------------
 
H

Helmut Weber

Hi Josha,

try this,
and test it in single step mode [F8 first]:

Sub Test56129A()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Font.AllCaps = True
While .Execute
rDcm.Select ' for testing, remove later
If Len(rDcm) <> 2 Then
rDcm.Font.AllCaps = False
rDcm.Text = UCase(rDcm.Text)
End If
rDcm.Collapse Direction:=wdCollapseEnd
Wend
End With
End Sub


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
J

Josha

Thanks, I gave it a go both with and without selecting all document text. For
some reason it didn't actually do anything, but the code was good, it didn't
produce an error or anything.

Any ideas?

Josha
 
H

Helmut Weber

Hi Josha,

what do you expect to see?
A character formatted as All caps
looks exactly the same as a proper uppercase character.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Helmut Weber

Hi Cindy,

or it is about Small caps and All caps.
Doesn't only sound similar,
looks similar as well.

:)

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
R

Russ

Josha,
Hi

I need to create a macro that will start at the begining of a Word document
and select all sections of text that are in ALLCAPS.

This might be the wrong approach depending on your control of the mail merge
process.
It then must change the
instances of all caps to title or proper caps. However there are specific two
letter codes that must remain as all caps. Is this possible?

Basically, a mail merge that uses a database query as the datasource is
importing address and name details in allcaps.
If you could control how to store the information in the database, that
would be best and would get rid of the problem.

Do you have control over the mail merge template? If so, I think you should
narrow your focus on the address parts of the mail merge document template
and bookmark the whole address field if the data is coming in as one big
chunk and run something like Jean Guy's (in the other message thread:
http://tinyurl.com/oujzw ) subroutine on that bookmark range. Or better yet,
bookmark and change to titlecase the individual fields, if the data is
merged as <firstname>,<lastname>, etc. I don't do mail merge, so I might be
missing some other more obvious techniques that apply to importing data into
a mail merge document. See this link for more information on Word mail
merge:
http://tinyurl.com/lbysu
 

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