what character is enter

F

filo666

I have the following code:

Sub quitarenter()
For cnt1 = 1 To characters.count
char = Selection.Characters(cnt1).Text
If char = Chr(10) Then
Characters(cnt1) = Chr(13)
End If
Next.

what I want to do is:
I'm importing from acrobat reader to word, a lot of (change of line)
characters appear in between sentences, what I want to do is to delete those
(change of line) (chr 10) to space and continuation of the sentence.

Remarks,
I ran the code and it did not work, frist of all the "characterscount" after
the "for" didnt work, and then the code never found chr(10) (change of line)

any suggestions??
TIA
 
H

Helmut Weber

Hi filo666,

a linebreak in Word is chr(11),
no matter what the help says.

It is chr(10) in Excel and maybe in other applications as well.

A character(13) is exactly that, chr(13),
but not a paragraph mark.

Try replacing chr(11) by "^p", like that:

Sub Test6777()
Dim rTmp As Range
Set rTmp = Selection.Range
With rTmp.Find
.Text = "^11"
.Replacement.Text = "^p"
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
End Sub

See also: http://gregmaxey.mvps.org/Replace_With_Paragraph.htm

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
F

filo666

It did not appear any error wathsoever, but it did not change anything,
please take an acrobat file and try, maybe the though character is not the
right one; by the way, how is Bavaria, is it a nice place??? it sound to me
like a interesting place!!!
 
F

filo666

please note the following code:

For cnt1 = 1 To 10000
char = ActiveDocument.Characters(cnt1)
If char = Chr(cnt1) Then
stop
End If

I determine that the character is char(13) so my new code is:

Sub quitarenter()
'ActiveDocument.Characters(1).Text = Chr(7)
For cnt1 = 1 To 10000000000#
char = ActiveDocument.Characters(cnt1)
ActiveDocument.Characters(cnt1).Select
If char = Chr(13) Then
ActiveDocument.Characters(cnt1).Text = Chr(7) & " "
End If
Next
End Sub

it takes hours to finish a 100 page document, could you help me to fasten it.

thanks.
 
T

Tony Jollans

The first thing to do is to ascertain what the character is. It would appear
it isn't chr(10). Select one of the characters and then go to the immediate
window in the VBE (Alt+F11, Ctrl+G) and type ?asc(selection). It will tell
you the character number.

Secondly why are you trying to replace it with chr(13), a carriage return?
You say you want a space, so use a space.
 
H

Helmut Weber

Hi Filo,

so you are copying text from a pdf-file,
paste it into Word and want to get rid of
the paragraph marks (chr13).


Try:

Sub Test456()
Dim rtmp As Range
Set rtmp = ActiveDocument.Range
With rtmp.Find
.Text = "^p"
.Replacement.Text = " " ' or whatever
.Execute Replace:=wdReplaceAll
End With
End Sub

or

Sub Test456()
Dim rtmp As Range
Set rtmp = ActiveDocument.Range
With rtmp.Find
.Text = Chr(13)
.Replacement.Text = Chr(32) ' or whatever
.Execute Replace:=wdReplaceAll
End With
End Sub

You don't even need a macro for that.

But note, that this will leave you
with a one-paragraph document!

I see no way, to distinguish programmatically
between paragraph marks you want to keep
and those you want to delete.

So better use the selection-object.

Sub Test456()
With Selection.Range.Find
.Text = Chr(13)
.Replacement.Text = Chr(32) ' or whatever
.Wrap = wdFindStop
.Execute Replace:=wdReplaceAll
End With
End Sub

Yes, Bavaria is a good place to live.
 

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