Programmatic change first space in each paragraph to a tab

B

Brian Holfield

abc def ghi
a bcd fgh i
ab cdfg hi
line 1, needs a tab instead of the space between c and d
line 2, needs a tab instead of the space between a and b
line 3, needs a tab instead of the space between b and c

Currently this is being done with a search and replace, using
wildcards:
Search for: (^013[! ]{1,})[space]
Replace with: \1^009

Is it possible to achieve the same result using a macro? Since a number
of people have to make this change, it would be easier to have them run
FirstSpaceToTab than to train them to use this tricky Search and
Replace.
Thanks for any help.
 
H

Helmut Weber

Hi Brian,

like this:

Sub test01()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "(^013[! ]{1,}) "
.Replacement.Text = "\1^009"
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
End Sub

As the search pattern you posted, doesn't get the first
space in the first paragraph of the doc, I didn't take
care of that small drawback either.
Maybe you don't need that feature at all.



--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Brian Holfield

Thanks, Helmut (thanks delayed by Christmas activity). This certainly
works nicely. First space unchanged is only a minor irritation that I
can live with. I do have to reboot into my American software partition,
as the wildcards seem to be different in my Czech partition and are a
complete mystery to me.
 
H

Helmut Weber

Hi Brian,

the list separator is "," in international versions,
or whatever you call it,
and ";" in banana republics.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Brian Holfield

Thanks again, Helmut. Seems odd that they'd use different formats, but
they do. Noticed the same thing with an Excel macro written in English
that wouldn't work in Czech Excel because the command names were
different. I would have thought that both languages would have worked,
but perhaps that's just my chauvinism at work.
 

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