Remove last character of found range

B

BP

Dear friends,

My problem is that I want to find each range formatted as
bold in a document and insert something at the beginning and
end of the range, which I did like so:

* Selection.Find.ClearFormatting
* Selection.Find.Replacement.ClearFormatting
* With Selection.Find
* .Font.Bold = True
* .Text = ""
* .Replacement.Font.Bold = True
* .Replacement.Text = "*^&*"
* .Forward = True
* .Wrap = wdFindContinue
* .Format = True
* End With
* Selection.Find.Execute Replace:=wdReplaceAll

Now the problem is that if the last character of the range
is a paragraph mark this mark is included and the closing
"*" ends up at the beginning of the next paragraph. I can
*not* fix it with:

* Selection.Find.ClearFormatting
* Selection.Find.Replacement.ClearFormatting
* With Selection.Find
* .Font.Bold = True
* .Text = "^p*"
* .Replacement.Text = "*^p"
* .Forward = True
* .Wrap = wdFindContinue
* .Format = True
* .MatchCase = False
* End With
* Selection.Find.Execute Replace:=wdReplaceAll

because in some cases there should be a "*" at the beginning
of a paragraph, and that should not be shifted to the end of
the preceding paragraph.

So what I need to do is to check if the last character of
the found range is a paragraph mark, and if it is insert the
"*" before the paragraph mark, but else just insert a "*" at
the end of the range.. How can I do that?

TIA,

/BP
 
H

Helmut Weber

Hi BP,

for tagging in general,
I remove formatting from paragraphs marks beforehand,
and not only from paragraph marks, but from other
control characters as well, like linefeed, end-of-cell,
end-of-row, new page, new section etc.
Bold text may spread over several paragraphs,
several cells. A paragraph mark may be bolded,
but be preceeded by not bold text and followed by bold text.

So just to deal with a paragraph mark,
if at the end of your found text,
may cure your problem today,
but wouldn't be a general solution.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

BP

Helmut Weber skrev:
Hi BP,

for tagging in general,
I remove formatting from paragraphs marks beforehand,

Yes, so obvious and I didn't think of it!
and not only from paragraph marks, but from other
control characters as well, like linefeed, end-of-cell,
end-of-row, new page, new section etc.

Yhe only ones of these I know how to search for are
^p = paragraph mark
^n = column break
^l = manual linebreak
^m = manual page break
^b = section break
how do I find the others?
Bold text may spread over several paragraphs,
several cells. A paragraph mark may be bolded,
but be preceeded by not bold text and followed by bold text.

Yes that too. IMHO it seems a bit daft that invisible characters
*can* have a style/format at all, especially as there is no italic
correction like in TeX anyway.
So just to deal with a paragraph mark,
if at the end of your found text,
may cure your problem today,
but wouldn't be a general solution.

Very true. BTW is there something like a
..Font.Normal property, or do I have to explicitly
set each possible styles to False?

Vielen Dank und Grüsse aus Schweden! :)
 
H

Helmut Weber

Hi BP,
Yhe only ones of these I know how to search for are
^p = paragraph mark
^n = column break
^l = manual linebreak
^m = manual page break
^b = section break
how do I find the others?

as to end-of-cell, end-of-row, not at all,
you can't search for them, as far as I know.

But don't worry, I think, I overdid it a bit
with mentioning them, too, being afraid of
having overlooked something.
If all of a cell is bold and you search for bold,
the end-of-cell is not encluded.

There is no font.normal property.
But there is range.font.reset,
which removes manual formatting.
Though, if a style is defined as bold
and text was manually unbolded,
it will be bold again.

FOr some more tipps on tagging,
google here for my decent name and "tagging".

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

BP

Hi Helmut,

Helmut said:
as to end-of-cell, end-of-row, not at all,
you can't search for them, as far as I know.

But don't worry, I think, I overdid it a bit
with mentioning them, too, being afraid of
having overlooked something.
If all of a cell is bold and you search for bold,
the end-of-cell is not encluded.

Ah OK. That may be good or bad. It so happens to be that I must find
some way of dealing with tables as well. Probably by hand-selecting
them and then run a macro which first turns the table into
tab-and-return-separated text and then inserts/replaces tabs and
returns with the appropriate tagging.
There is no font.normal property.
But there is range.font.reset,
which removes manual formatting.
Though, if a style is defined as bold
and text was manually unbolded,
it will be bold again.

Ah, OK. Then I'll have to use .Font.Bold = False, as I do have to deal
with heading styles defined as bold (and italic, and underline...)
FOr some more tipps on tagging,
google here for my decent name and "tagging".

Found them! I thought I was the only one in the world who'd want to do
something even akin to turning DOC format into wikitext. Good to see
it is not so! I wasn't aware of .InsertBefore and
..InsertAfter, but clearly they are better than using
"openingTag^&closing tag" as replacement text!

Thanks a lot!
 
H

Helmut Weber

Hi BP,

actually, I don't know about wikitext.
My attempt was to convert Word-files
to txt-files tagged for QuarkXpress.

As Xpress AFAIK has not concept of tables,
Word-tables had to be converted to plain text.
Might be the same with wikitext.

Its a hell of a job.

One step is to find out the maximum number
of lines in a cell in a row.
Then add empty lines to every cell in that row,
which contains less than the maximum number of lines.
And taking care of end-of-line hyphens, too,
and convert it to ordinary hyphens and linefeeds.

The code I used is somewhere buried
in one of my office PCs.
Maybe some hundred lines.

But it's possible.

You could even convert a cross-word-puzzle
in form of a Word-table to plain text
and keep all of the information.

I wish you better luck than I had,
as nobody in our layout department for print
could understand what was going on.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

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