Discussion:
Zeilenumbrüche entfernen
(zu alt für eine Antwort)
Heinrich Wolf
2006-08-29 16:14:30 UTC
Permalink
Hallo,

Zum Umformatieren von Usenet-Beiträgen suche ich ein VBA-Makro.

Jedes Zeilenende hat ein Absatzzeichen,
und die Absätze sind mit einem weiteren Absatzzeichen getrennt.
D.h. es ist eigentlich fortlaufend dasselbe,
nur ist die visuelle Absatztrennzeile eben eine Leerzeile.

Gefragt wäre also ein Makro,
das alle am Ende einer Textzeile
stehenden Absatzzeichen herausnimmt,

diese aber stehen lässt,

wenn es tatsächlich das Ende eine Absatzes ist,
d.h. am Ende der letzten Zeile eines Absatzes,
und in der Leerzeile selber.

Und am Dokumentende wird die Arbeit beendet.

Ich hatte mal so ein Macro, selbstgestrickt unter Word-Basic,
aber mit VBA habe ich mich nie befasst.

Word 2000

Wer mag mir helfen?
Vielen Dank im Voraus
Heinrich
Helmut Weber
2006-08-29 20:05:37 UTC
Permalink
Hallo Heinrich,

ohne auf mögliche Komplikationen einzugehen:

Sub Test567()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "^13{2,}" ' zwei oder mehr
.MatchWildcards = True
.Replacement.Text = "#-#-"
' "#-#-" Das ist der Knackpunkt
' funktioniert praktisch, aber nicht thoeoretisch
' aber wird schon klappen
.Execute Replace:=wdReplaceAll
End With
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "^13"
.Replacement.Text = " "
.Execute Replace:=wdReplaceAll
.Text = "#-#-"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
End With
End Sub
--
Gruß

Helmut Weber, MVP WordVBA

"red.sys" & chr$(64) & "t-online.de"
Win XP, Office 2003 (US-Versions)
Heinrich Wolf
2006-08-30 08:32:06 UTC
Permalink
Post by Helmut Weber
Hallo Heinrich,
Sub Test567()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "^13{2,}" ' zwei oder mehr
.MatchWildcards = True
.Replacement.Text = "#-#-"
' "#-#-" Das ist der Knackpunkt
' funktioniert praktisch, aber nicht thoeoretisch
' aber wird schon klappen
.Execute Replace:=wdReplaceAll
End With
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "^13"
.Replacement.Text = " "
.Execute Replace:=wdReplaceAll
.Text = "#-#-"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
End With
End Sub
Danke, Helmut

Hat leider nicht funktioniert.
Bekomme diese Meldung:
"Laufzeitfehler 5560, Der Text im Feld 'Suchen
nach' enthält einen ungültigen Mustervergleich"
und die Zeile
.Execute Replace:=wdReplaceAll
wird gelb markiert.

Ich füge hier einen typischen Mustertext bei:

*************
Post by Helmut Weber
Hi everyone,
I am using a trial version of this software, and although I consider myself
computer literate and savvy, I feel very dumb with this program.
If you have not used an image editor before you will have some
learning to do, no matter whose program you use. However, the
number of learning resources for Corel Paint Shop Pro is limited.
Post by Helmut Weber
I have no
clue what I'm doing and I'm using it on a trial and error basis.
While the Help in the current version is very sparse, you should
at least review it to have a general idea about some of the things
the program can do and how it does them.
Post by Helmut Weber
I am
currently setting up a website and wanted to create my own graphic image as
a background for the website. The image came out beautiful, however, there
are some things that have me going nuts. If anyone can help me with this,
it would be greatly, greatly appreciated, as I'm at my wit's end with this.
1) How do you go back and edit an image after you have saved it?
The simple answer is that you re-open the image with File > Open
and use whatever tools you want on it. If you save your image in
Paint Shop Pro Image (.PspImage) format then all the separate
elements (such as layers or vector objects) from which the image
is made are retained. When you re-open the image they are there
the way they were at the time you saved. However, if you save in
most other formats the image is flattened into a single layer of
colored pixels without editable objects. This can make it hard to
change some of the things that were in the image originally after
re-opening the image since now these individual items are no
longer present in the image. You didn't tell us in what format
you are saving your image. I don't know why.
Post by Helmut Weber
For
example, if you want to erase something you did and do it over, the eraser
tool does not do anything at all.
<gekürzt>
Post by Helmut Weber
Please help!!
Mari
*************

Es braucht keine perfekte Lösung zu sein. Da ich die Texte ohnehin
genau lese, kann ich alle Feinarbeit gut von Hand machen. Im Wesent-
lichen sollten einfach die Zeilen der Abschnitte zu einem fortlau-
fenden Satz werden.

Bei den zitierten Abschnitten sollen die ">" jedoch im laufenden Satz
erhalten bleiben, so dass immer klar bleibt, was Zitat und was
Antwort ist.

Vielen Dank
Heinrich
Helmut Weber
2006-08-30 08:42:02 UTC
Permalink
Hallo Heinrich,

passiert leider immer wieder,
wenn man mit einer US-Version testet.
.Text = "^13{2,}" ' zwei oder mehr, US-Version mit Komma
.Text = "^13{2;}" ' zwei oder mehr ' deutsche Version mit Semikolon

Helmut Weber
Heinrich Wolf
2006-08-30 12:48:11 UTC
Permalink
Post by Helmut Weber
passiert leider immer wieder,
wenn man mit einer US-Version testet.
.Text = "^13{2,}" ' zwei oder mehr, US-Version mit Komma
.Text = "^13{2;}" ' zwei oder mehr ' deutsche Version mit Semikolon
Ja, das Sprachenproblem ist einer der grössten Fallstricke in der
Computerei. Ich habe jetzt mit "Paint Shop Pro" gegen gutes Geld
von DE auf US umgestellt.

Mit deinem "Schuhlöffel" habe ich das Makro noch so frisiert,
dass es genau nach Wunsch funktioniert, d.h. die beabsichtigten
Absätze bestehen lässt. Funktioniert toll!

Mit ganz vielem Dank
Heinrich Wolf


Sub Wordwrap_ex()
'
' Wordwrap_ex Makro
' Makro von Helmut Weber, MVP WordVBA
'
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "^13{2;}" ' zwei oder mehr
.MatchWildcards = True
.Replacement.Text = "#-#-"
' "#-#-" Das ist der Knackpunkt
' funktioniert praktisch, aber nicht thoeoretisch
' aber wird schon klappen
.Execute Replace:=wdReplaceAll
End With
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "^13"
.Replacement.Text = " "
.Execute Replace:=wdReplaceAll
End With
With rDcm.Find
.Text = "#-#-"
.Replacement.Text = "^13^13"
.Execute Replace:=wdReplaceAll
End With
End Sub
Helmut Weber
2006-08-30 15:36:25 UTC
Permalink
Hallo Heinrich,

noch ein Wort der Warnung,
Post by Heinrich Wolf
.Replacement.Text = "^13^13"
erzeugt keine Absatzmarken.
Eine Absatzmarke ist mehr als chr(13).

Verwende

.Replacement.Text = "^p^p"

Testen mit:

MsgBox ActiveDocument.Range.Paragraphs.Count

in der einen und der anderen Variante.
--
Gruß

Helmut Weber, MVP WordVBA

"red.sys" & chr$(64) & "t-online.de"
Win XP, Office 2003 (US-Versions)
Heinrich Wolf
2006-08-30 17:42:15 UTC
Permalink
Helmut

Alles klar und nochmals vielen Dank
Heinrich

Lesen Sie weiter auf narkive:
Loading...