PDA

View Full Version : Hypen (-) is not recognized as paragraph begin



dagerr
11-23-2018, 06:51 AM
Hi, a following code not working when at begin of paragraph occurs hypen, how to solve this.
File to testing: 23258



Sub add_before_xml()

Dim bRng As Range
Set bRng = ActiveDocument.Range
With bRng.Find


With .Font
.Size = 8
.Underline = wdUnderlineSingle
End With

Do While .Execute(MatchWholeWord:=True)


bRng.End = bRng.Paragraphs(1).Range.End - 1
With bRng
.InsertBefore "<tr><td>"
.InsertAfter "</td></tr>"
.Collapse 0
End With

Loop
End With
lblb_Exit:
Set bRng = Nothing

End Sub

gmaxey
11-23-2018, 07:30 AM
It seems to work here. You are going to have to do a better job at providing and example. What specifically isn't working. Show us a small sample of text before and after your process. Showing what you start with, what you get, and what you expect to get.

dagerr
11-23-2018, 10:01 AM
ok,
text before:
1. San-Pajda 7 21 21:2
2. PZPS Szczyrk 7 16 18:7
3. Tomasovia 7 16 18:8
8. Marba 7 4 6:19
- - - -
9. Pogon 7 4 7:20
- - -

Text after process:

<tr><td>1. San-Pajda 7 21 21:2</td></tr>
<tr><td>2. PZPS Szczyrk 7 16 18:7</td></tr>
<tr><td>3. Tomasovia 7 16 18:8</td></tr>
<tr><td>8. Marba 7 4 6:19</td></tr>
- - - -
<tr><td>9. Pogon 7 4 7:20</td></tr>
- - -

My expectation:

<tr><td>1. San-Pajda 7 21 21:2</td></tr>
<tr><td>2. PZPS Szczyrk 7 16 18:7</td></tr>
<tr><td>3. Tomasovia 7 16 18:8</td></tr>
<tr><td>8. Marba 7 4 6:19</td></tr>
<tr><td>- - - -<tr><td>
<tr><td>9. Pogon 7 4 7:20</td></tr>
<tr><td>- - - </tr></td>

gmaxey
11-23-2018, 01:32 PM
Well, I'm sorry, but your code as posted does not produce what you show as "Text after process" (at least not here). What are really trying to do? Since everything in your example text is underlined, why are bothering to find underline?

dagerr
11-23-2018, 01:53 PM
Well, I'm sorry, but your code as posted does not produce what you show as "Text after process" (at least not here). What are really trying to do? Since everything in your example text is underlined, why are bothering to find underline?

I don't know what is wrong but code doesn't insert before and doesn't insert after any desired text, where paragraph start with hypen, i've check it on two different computers. How I should prove it for You?
I've added underline because my document has much more different types format of text.

gmaxey
11-23-2018, 02:29 PM
Try:


Sub add_before_xml()
Dim bRng As Range
Dim oPar As Paragraph
Set bRng = ActiveDocument.Range
With bRng.Find
With .Font
.Size = 8
.Underline = wdUnderlineSingle
End With
Do While .Execute(MatchWholeWord:=True)
bRng.End = bRng.Paragraphs(1).Range.End - 1
With bRng
.Select
.InsertBefore "<tr><td>"
.InsertAfter "</td></tr>"
.Collapse 0
End With
Loop
End With
For Each oPar In ActiveDocument.Range.Paragraphs
If oPar.Range.Characters.First = "-" And Not InStr(oPar.Range.Text, "<tr>") > 0 Then
oPar.Range.InsertBefore "<tr><td>"
oPar.Range.InsertAfter "</tr></td>"
End If
Next
lblb_Exit:
Set bRng = Nothing
End Sub