Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2006

Tip: Looking for answers? Try searching our database.

Remove last character of found range

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BP - 20 Dec 2006 09:17 GMT
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
Helmut Weber - 20 Dec 2006 10:15 GMT
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.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

>Dear friends,
>
[quoted text clipped - 45 lines]
>
>/BP
BP - 20 Dec 2006 21:23 GMT
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?

> --
> Greetings from Bavaria, Germany

Vielen Dank und Gr?sse aus Schweden! :-)

> Helmut Weber, MVP WordVBA
>
[quoted text clipped - 51 lines]
> >
> >/BP
Helmut Weber - 21 Dec 2006 03:55 GMT
Hi BP,

>Yhe only ones of these I know how to search for are
>^p = paragraph mark
[quoted text clipped - 3 lines]
>^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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

BP - 22 Dec 2006 18:20 GMT
Hi Helmut,

> as to end-of-cell, end-of-row, not at all,
> you can't search for them, as far as I know.
[quoted text clipped - 4 lines]
> 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!

> HTH

Thanks a lot!
Helmut Weber - 22 Dec 2006 22:47 GMT
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.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.