MS Office Forum / Word / Programming / January 2008
what character is enter
|
|
Thread rating:  |
filo666 - 13 Jan 2008 13:44 GMT 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
Helmut Weber - 13 Jan 2008 14:07 GMT 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
filo666 - 13 Jan 2008 19:14 GMT Thanks for answering, but it did not work out, any idea???
> Hi filo666, > [quoted text clipped - 28 lines] > > Vista Small Business, Office XP Helmut Weber - 13 Jan 2008 22:19 GMT Hi,
>it did not work out, any idea??? which is kind of a spare error description, if there is an error at all.
see in addition: http://www.google.com/custom?hl=de&cof=S:http://www.mvps.org%3BL:http://www.mvps .org/images/mvp.gif%3BLH:89%3BLW:108%3B&sitesearch=mvps.org&sa=X&oi=spell&resnum =0&ct=result&cd=1&q=clean+web&spell=1
and http://gregmaxey.mvps.org/Clean_Up_Text.htm
--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Vista Small Business, Office XP
Helmut Weber - 13 Jan 2008 22:24 GMT that first link should be
http://word.mvps.org/FAQs/Formatting/CleanWebText.htm
--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Vista Small Business, Office XP
filo666 - 14 Jan 2008 09:27 GMT 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!!!
> that first link should be > [quoted text clipped - 7 lines] > > Vista Small Business, Office XP filo666 - 14 Jan 2008 10:14 GMT 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.
> 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 [quoted text clipped - 12 lines] > > > > Vista Small Business, Office XP Helmut Weber - 14 Jan 2008 13:05 GMT 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.
 Signature Helmut Weber, MVP WordVBA "red.sys" & chr(64) & "t-online.de" Word 2002, Windows 2000 (german versions)
Tony Jollans - 14 Jan 2008 11:54 GMT 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.
 Signature Enjoy, Tony
>I have the following code: > [quoted text clipped - 20 lines] > any suggestions?? > TIA
|
|
|