Locating and changing formatting

B

BurtArkin

I am importing large amounts of data for a quasi-legal document into Word,
from Access, using mailmerge. I have set markers in the text being imported,
like "<ZZ" and "BLD". <ZZ is converted to a tab easily enough with a short
macro. BLD is placed at the front of a line I want to change to boldface or
italic. How do I do this with a macro? I'd appreciate any help you can
gfive. Thanks.
 
N

Ness

Burt,
Try:
Selection.Find.ClearFormatting
With Selection.Find
.Text = "bld"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
'to change line to bold
Selection.Font.Bold = wdToggle
'to change to italic
Selection.Font.Italic = wdToggle

Hope this helps
 
T

Tony Jollans

When you say "line" what exactly do you mean? Word doesn't really have a
line as a unit because it depends on the printer being used.

It is possible to select what you see as a line on the screen (and to do it
in code with the Selection object) but if when you say "line" you mean text
that is actually delimited in some other way - perhaps with a new line mark
or paragraph mark - then the changes you want could be quite easily done
with Find/Replace (and code could be recorded if you want it).

As I write, I realise, of course, that code could be recorded anyway - it
would just be more complex both manually and in code if you really want to
work with a 'screen line' which is not delimited in any other way.
 
B

BurtArkin

Thank you for your response. It works, but only for a single instance of the
"BLD" element. There are always a variable number of markers in the doc I'm
merging, and I need to "loop" through the entire merged text. I've attempted
to create the looping code, but I'm doing something wrong, because it never
ends. Thanks again for your help.
 
B

BurtArkin

Thanks for your response. By line, I meant a paragraph header. There are
several in the document that I merge into Word, and I want to bold and/or
italicize the lines that start with ther letters "BLD"
 
T

Tony Jollans

If I understand what you mean by "paragraph header" you should be able to
use a Find/Replace

Open up the Find/Replace Dialog
Press More if need be to see the whole thing
Check Use Wildcards

Find <BLD([!^13]{1,}^13) -- that's less than symbol, B, L, D, left
parenthesis, left (square) bracket, exclamation point, caret, one, three,
right bracket, left brace, one, comma, right brace, caret, one, three, right
parenthesis

Replace \1 -- that's backslash, one

Set Replace format to Bold (cursor in Replace, Click on Format, Select Font,
Choose Bold, Close)

Hit Replace All

(untested so I might have made a typo - or other stupid mistake :)
 

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