Find.Replace() Indent to Tab.

E

Esteban

Does anyone know how to use the Find.Replace function
within Word VBA to find paragraph FirstLineIndents and
change them to tabs?
When I use this function, it simply selects any
paragraph that has the specified FirstLineIndent and
replaces the entire paragraph with a tab, as opposed to
simply replacing the indent with the tab.
VBA does the same regardless of whether I specify the
search criterion as text (e.g., text = ""), or as a
paragraph format (e.g., paragraph.format = "") within the
Find fields.
I suspect I may have to create a custom style sheet and
use the Find.Replace feature to globally replace one style
for another.
However, is there a way that I can simply modify the
Find.Replace code so that it does not delete the entire
paragraph, but rather only replace the indent with a tab?
Thank you...
 
J

JGM

Hi Esteban,

Technically speaking, you cannot replace an FirstLineIndent by a tab. A tab
is a character, an FirstLineIndent is a pargraph formatting. It is like if
you tried to directly replace Italic formatting by the number 2... it just
does not make sense.

So, what you want to do is find those paragraph that have the offending
FirstLineIndent, set the first line indent for those paragraph to 0, place
the cursor at the beginning of the said paragraph and type in a Tab... If
all the paragraphs witht the FirstLineIndent to be removed are of the same
style, you could consider modifying the style instead...

But why on Earth do you want to replace a perfectly good first line indent
by an ackward-to-use-in-this-situation Tab? First line indents are easy to
manage. Just create a style an apply the style to any paragraph. If later
you want to change the with/spacing of the indent, just change the style
defintion, and Voila, all the concerned paragraphs are adjusated in one
simple operation... Just a thought...

HTH
Cheers!
 
L

Larry

In addition to what JGM said, Word works more efficiently with
first-line indents than with tabs. Let's say your cursor is in the
middle of a paragraph and you want to bring it to the first word of the
paragraph. If you press Ctrl+Up arrow (ParaUp), the cursor will move to
the left edge of the first line of the paragraph, to the left of the
empty tabbed space. You still have to move the cursor one word right to
get it to the opening word of the paragraph. This is because Word reads
the tab as a character. But if the paragraph is formatted with a
first-line indent, then running the ParaUp command moves the cursor
directly to the first word of the paragraph.

Larry
 
K

Klaus Linke

Still, there might be valid reasons to put a tab in front of indented
paragraphs, and remove the indent.
For example to convert a document into a format that doesn't know about
indents.

You could do it with a wildcard replacement, I think.

Find what: *^13 ((with Format > Paragraph > indent = whatever))
Replace with: ^t^& ((Format > Paragraph > indent = 0))

Looking for *^13 makes sure that the text is matched one paragraph at a
time.
^13 is the paragraph mark, ^t a tab, ^& the matched text.

If you don't know the indent beforehand, or want to put in more than one tab
for larger indents, it might make more sense to loop "For Each myParagraph
in ActiveDocument.Paragraphs", check the indent, remove it, and add the
tab(s).

Greetings,
Klaus
 

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