Silly beginers question

J

Jack

I have the following text, 50 pages full, the <> stuff is mine ;

Text text text text.....
<bg>abcdef two three
six seven eight
David three <be>
Text text text text.....
Text text text text.....
<bg>Thirty Six
Apple Pear<be>
Text text text text.....
Text text text text.....
etc.....

How can I setup a Macro/vb code to put a Right tab in front of these lines
begining with <bg> and ending with with <be>?

Or is there a better way of doing this?
Many thanks
 
K

Klaus Linke

Hi Jack,

If you want the lines between <bg> and <be> right-adjusted, you can use
"Find/Replace", with "Match wildcards" checked:
Find what: \<bg\>*\<be\>
Replace with: ^& ((either replace with a right-adjusted style, or appy
"Format > Paragraph > Adjustment=Right" as manual formatting))

Since < and > have a special meaning in wildcard searches, you have to use
\< and \> instead.
The * wildcard matches anything between <bg> and <be>.

Regards,
Klaus
 
J

Jack

WOW!
I never knew that you can do these things, without even using VB!

Thank you very much Klaus
 
J

Jack

Thanks It works fine

However when I do it in "real" mode I can cancel the Find box then move my
cursor to the left of the highlighted text, then press Tab and it inserts a
Tab in front of the text.
However when I do it in Macro record Mode my Tab key overwrites the
highlighted text instead of moving it forward.

Any ideas how to overcome this overwriting problem?

Thanks for your valuable time
J
 
M

Mark Tangard

Jack,

Do you always want a tab before the replacement? If so,
just add:

^t

in front of what the macro records as:

.Replacement.Text = ____

If you only want a tab in some cases, that's possible
also, assuming there's some sort of pattern to what
triggers that.
 
J

Jack

Thanks Mark

I want it to highlight 1 or more lines then to add a Tab character in front
of all the selected lines. I can do it using the above find formula then
adding a Tab key. But it won't do it when in Play or Record macro.
 
M

Mark Tangard

This points out the limitations of recorded macro code. There's
no way for the recorder to capture what you do when you escape
the Find dialog and press Tab. But as I say, if you look at the
code it creates -- have you learned to do that? -- there'll be
a line right in the middle of it of the form:

.Replacement.Text = [probably ^& if I read the thread right]

Just change that line to:

.Replacement.Text = ^t^&

and run the macro.

When you say you want it to highlight 1 or more lines, the Find
dialog won't do that, and your macro won't either without a lot
of extra code -- highlight several lines *at once*, if that's
how I hear you. I gather you're looking for a way to simulate
the native formatting of the code you're creating. This is
always tempting given Word's powerful editing capacity (and
the crappy editing abilities of most other programs), but it's
not often something onto which you can project the same sort
of motions. You *can* indent a block of text in Word with
the tab key, but it'd be a bit of a chore to write a macro
that selects such a block (of varying length, even) & then
indents it.
 
J

Jack

Hi Mark
^&
works fine. Very Nice.

Sorry I've been wasting my own and everybody else's time the Tab key doesn't
insert Tab characters it only Indents it but I must have Tabs. It doesn't do
that so there is now way I can automate it.

But I can use my new knowledge and try some other approaches.

J

Mark Tangard said:
This points out the limitations of recorded macro code. There's
no way for the recorder to capture what you do when you escape
the Find dialog and press Tab. But as I say, if you look at the
code it creates -- have you learned to do that? -- there'll be
a line right in the middle of it of the form:

.Replacement.Text = [probably ^& if I read the thread right]

Just change that line to:

.Replacement.Text = ^t^&

and run the macro.

When you say you want it to highlight 1 or more lines, the Find
dialog won't do that, and your macro won't either without a lot
of extra code -- highlight several lines *at once*, if that's
how I hear you. I gather you're looking for a way to simulate
the native formatting of the code you're creating. This is
always tempting given Word's powerful editing capacity (and
the crappy editing abilities of most other programs), but it's
not often something onto which you can project the same sort
of motions. You *can* indent a block of text in Word with
the tab key, but it'd be a bit of a chore to write a macro
that selects such a block (of varying length, even) & then
indents it.

--
Mark Tangard <[email protected]>, Microsoft Word MVP
Please reply only to the newsgroup, not by private mail.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters

Thanks Mark

I want it to highlight 1 or more lines then to add a Tab character in front
of all the selected lines. I can do it using the above find formula then
adding a Tab key. But it won't do it when in Play or Record macro.

move
my can
use have to
use
 
K

Klaus Linke

Hi Jack,
Sorry I've been wasting my own and everybody else's time
the Tab key doesn't insert Tab characters it only Indents it
but I must have Tabs.

That depends on some setting "Tools > Options > Edit" ("Set left indent
using Tab and Backspace keys" or something like that). But if you insert a
tab ^t with "Find/Replace", that always really inserts a tab.

It doesn't do that so there is now way I can automate it.

You could do it with two searches.
I guess the first wildcard search worked for you and right-adjusted all
paragraphs that you want to get a tab?
Then do that first, and then do a second wildcard replacement:
Find what: *^13 ((with "Format > Paragraph > Adjustment: Right"))
Replace with: ^t^& ((with "Format > Paragraph > Adjustment: Left"))

The wildcard search *^13 makes sure you match one paragraph at a time. ^t
is the tabulator you want to insert, and ^& the matched text.

Regards,
Klaus
 
M

Mark Tangard

Jack,

Don't give up yet. The TAB key only indents if you have
the 'Tab and Backspace set Left Indent' box checked under
Tools­> Options­> Edit.

It's one of those options that folks always seems to end
up needing checked the opposite way from how it is...

--
Mark Tangard <[email protected]>, Microsoft Word MVP
Please reply only to the newsgroup, not by private email.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters


Hi Mark
^&
works fine. Very Nice.

Sorry I've been wasting my own and everybody else's time the Tab key doesn't
insert Tab characters it only Indents it but I must have Tabs. It doesn't do
that so there is now way I can automate it.

But I can use my new knowledge and try some other approaches.

J

Mark Tangard said:
This points out the limitations of recorded macro code. There's
no way for the recorder to capture what you do when you escape
the Find dialog and press Tab. But as I say, if you look at the
code it creates -- have you learned to do that? -- there'll be
a line right in the middle of it of the form:

.Replacement.Text = [probably ^& if I read the thread right]

Just change that line to:

.Replacement.Text = ^t^&

and run the macro.

When you say you want it to highlight 1 or more lines, the Find
dialog won't do that, and your macro won't either without a lot
of extra code -- highlight several lines *at once*, if that's
how I hear you. I gather you're looking for a way to simulate
the native formatting of the code you're creating. This is
always tempting given Word's powerful editing capacity (and
the crappy editing abilities of most other programs), but it's
not often something onto which you can project the same sort
of motions. You *can* indent a block of text in Word with
the tab key, but it'd be a bit of a chore to write a macro
that selects such a block (of varying length, even) & then
indents it.

--
Mark Tangard <[email protected]>, Microsoft Word MVP
Please reply only to the newsgroup, not by private mail.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters

Thanks Mark

I want it to highlight 1 or more lines then to add a Tab character in front
of all the selected lines. I can do it using the above find formula then
adding a Tab key. But it won't do it when in Play or Record macro.

Jack,

Do you always want a tab before the replacement? If so,
just add:

^t

in front of what the macro records as:

.Replacement.Text = ____

If you only want a tab in some cases, that's possible
also, assuming there's some sort of pattern to what
triggers that.

--
Mark Tangard <[email protected]>, Microsoft Word MVP
Please reply only to the newsgroup, not by private mail.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters



Jack wrote:

Thanks It works fine

However when I do it in "real" mode I can cancel the Find box then move
my
cursor to the left of the highlighted text, then press Tab and it
inserts a
Tab in front of the text.
However when I do it in Macro record Mode my Tab key overwrites the
highlighted text instead of moving it forward.

Any ideas how to overcome this overwriting problem?

Thanks for your valuable time
J
Hi Jack,

If you want the lines between <bg> and <be> right-adjusted, you can
use
"Find/Replace", with "Match wildcards" checked:
Find what: \<bg\>*\<be\>
Replace with: ^& ((either replace with a right-adjusted style, or
appy
"Format > Paragraph > Adjustment=Right" as manual formatting))

Since < and > have a special meaning in wildcard searches, you have to
use
\< and \> instead.
The * wildcard matches anything between <bg> and <be>.

Regards,
Klaus



I have the following text, 50 pages full, the <> stuff is mine ;

Text text text text.....
<bg>abcdef two three
six seven eight
David three <be>
Text text text text.....
Text text text text.....
<bg>Thirty Six
Apple Pear<be>
Text text text text.....
Text text text text.....
etc.....

How can I setup a Macro/vb code to put a Right tab in front of
these lines begining with <bg> and ending with with <be>?

Or is there a better way of doing this?
Many thanks
 
J

Jack

Klaus!
What should I say? I'm open mouthed by the way you don't give up and just
keep coming up with solutions.
I managed to finish the job in a bit of a long winded way but your solution
is so... elegant.

Thanks again Klaus.
 
J

Jack

Thanks Mark I've learned something new today.
I'll check it out.

Best wishes
J
Mark Tangard said:
Jack,

Don't give up yet. The TAB key only indents if you have
the 'Tab and Backspace set Left Indent' box checked under
Tools­> Options­> Edit.

It's one of those options that folks always seems to end
up needing checked the opposite way from how it is...

--
Mark Tangard <[email protected]>, Microsoft Word MVP
Please reply only to the newsgroup, not by private email.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters


Hi Mark
^&
works fine. Very Nice.

Sorry I've been wasting my own and everybody else's time the Tab key doesn't
insert Tab characters it only Indents it but I must have Tabs. It doesn't do
that so there is now way I can automate it.

But I can use my new knowledge and try some other approaches.

J

Mark Tangard said:
This points out the limitations of recorded macro code. There's
no way for the recorder to capture what you do when you escape
the Find dialog and press Tab. But as I say, if you look at the
code it creates -- have you learned to do that? -- there'll be
a line right in the middle of it of the form:

.Replacement.Text = [probably ^& if I read the thread right]

Just change that line to:

.Replacement.Text = ^t^&

and run the macro.

When you say you want it to highlight 1 or more lines, the Find
dialog won't do that, and your macro won't either without a lot
of extra code -- highlight several lines *at once*, if that's
how I hear you. I gather you're looking for a way to simulate
the native formatting of the code you're creating. This is
always tempting given Word's powerful editing capacity (and
the crappy editing abilities of most other programs), but it's
not often something onto which you can project the same sort
of motions. You *can* indent a block of text in Word with
the tab key, but it'd be a bit of a chore to write a macro
that selects such a block (of varying length, even) & then
indents it.

--
Mark Tangard <[email protected]>, Microsoft Word MVP
Please reply only to the newsgroup, not by private mail.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters


Jack wrote:

Thanks Mark

I want it to highlight 1 or more lines then to add a Tab character
in
front
of all the selected lines. I can do it using the above find formula then
adding a Tab key. But it won't do it when in Play or Record macro.

Jack,

Do you always want a tab before the replacement? If so,
just add:

^t

in front of what the macro records as:

.Replacement.Text = ____

If you only want a tab in some cases, that's possible
also, assuming there's some sort of pattern to what
triggers that.

--
Mark Tangard <[email protected]>, Microsoft Word MVP
Please reply only to the newsgroup, not by private mail.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters



Jack wrote:

Thanks It works fine

However when I do it in "real" mode I can cancel the Find box
then
move
my
cursor to the left of the highlighted text, then press Tab and it
inserts a
Tab in front of the text.
However when I do it in Macro record Mode my Tab key overwrites the
highlighted text instead of moving it forward.

Any ideas how to overcome this overwriting problem?

Thanks for your valuable time
J
Hi Jack,

If you want the lines between <bg> and <be> right-adjusted,
you
can
use
"Find/Replace", with "Match wildcards" checked:
Find what: \<bg\>*\<be\>
Replace with: ^& ((either replace with a right-adjusted style, or
appy
"Format > Paragraph > Adjustment=Right" as manual formatting))

Since < and > have a special meaning in wildcard searches, you have to
use
\< and \> instead.
The * wildcard matches anything between <bg> and <be>.

Regards,
Klaus



I have the following text, 50 pages full, the <> stuff is mine ;

Text text text text.....
<bg>abcdef two three
six seven eight
David three <be>
Text text text text.....
Text text text text.....
<bg>Thirty Six
Apple Pear<be>
Text text text text.....
Text text text text.....
etc.....

How can I setup a Macro/vb code to put a Right tab in front of
these lines begining with <bg> and ending with with <be>?

Or is there a better way of doing this?
Many thanks
 

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