Answered by:
Problem trying to wrap a Microsoft Word paragraph in XML tags?!? :/

Question
-
Hello everyone. I really hope this is not a big problem and that some of your could help. I wrote a Macro in VBA like a year ago that was intented to put a tag before every single paragraph in a document. The logic validates that the paragraph have no other tag before putting one. All of this is based in styles. Some font styles would end up with different tags. This is my code and it works:
Sub edictos() ' ' ' Edictos de El Nuevo Día ' 06/20/2005 by Carlos Stella Sistemas de Información ' Actualización 08/08/2012 '------------------------------------------------------ 'Ver 2.0 made by Samuel Otero -> 07/26/2013 Dim oPara As Paragraph Dim oRng As Range 'Borramos headers y footers Call ClearHeaderFooters 'Borramos column breaks Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "^n" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll 'Lógica para poner los tags de Tera donde van For Each oPara In ActiveDocument.Paragraphs If oPara.Range.Style = "C10" Then If InStr(1, oPara.Range.Text, "(intro)") = 0 And _ InStr(1, oPara.Range.Text, "(main)") = 0 And _ InStr(1, oPara.Range.Text, "(capara)") = 0 Then oPara.Range.InsertBefore "(intro) " End If End If If oPara.Range.Style = "J10" Then If InStr(1, oPara.Range.Text, "(intro)") = 0 And _ InStr(1, oPara.Range.Text, "(main)") = 0 And _ InStr(1, oPara.Range.Text, "(capara)") = 0 Then oPara.Range.InsertBefore "(intro) " End If End If If oPara.Range.Style = "J12" Then If InStr(1, oPara.Range.Text, "(intro)") = 0 And _ InStr(1, oPara.Range.Text, "(main)") = 0 And _ InStr(1, oPara.Range.Text, "(capara)") = 0 Then oPara.Range.InsertBefore "(intro) " End If End If If oPara.Range.Style = "LE" Then If InStr(1, oPara.Range.Text, "(intro)") = 0 And _ InStr(1, oPara.Range.Text, "(main)") = 0 And _ InStr(1, oPara.Range.Text, "(capara)") = 0 Then oPara.Range.InsertBefore "(main) " End If End If If oPara.Range.Style = "XL" Then If InStr(1, oPara.Range.Text, "(intro)") = 0 And _ InStr(1, oPara.Range.Text, "(main)") = 0 And _ InStr(1, oPara.Range.Text, "(capara)") = 0 Then oPara.Range.InsertBefore "(main) " End If End If If oPara.Range.Style = "MF" Then If InStr(1, oPara.Range.Text, "(intro)") = 0 And _ InStr(1, oPara.Range.Text, "(main)") = 0 And _ InStr(1, oPara.Range.Text, "(capara)") = 0 Then oPara.Range.InsertBefore "(main) " End If End If If oPara.Range.Style = "HG" Then If InStr(1, oPara.Range.Text, "(intro)") = 0 And _ InStr(1, oPara.Range.Text, "(main)") = 0 And _ InStr(1, oPara.Range.Text, "(capara)") = 0 Then oPara.Range.InsertBefore "(main) " End If End If If oPara.Range.Style = "LW" Then If InStr(1, oPara.Range.Text, "(intro)") = 0 And _ InStr(1, oPara.Range.Text, "(main)") = 0 And _ InStr(1, oPara.Range.Text, "(capara)") = 0 Then oPara.Range.InsertBefore "(main) " End If End If If oPara.Range.Style = "J8" Then If InStr(1, oPara.Range.Text, "(intro)") = 0 And _ InStr(1, oPara.Range.Text, "(main)") = 0 And _ InStr(1, oPara.Range.Text, "(capara)") = 0 Then oPara.Range.InsertBefore "(main) " End If End If ' Agarrando texto sin estilo >_> If oPara.Range.Font.Size <= 6 Then If InStr(1, oPara.Range.Text, "(intro)") = 0 And _ InStr(1, oPara.Range.Text, "(main)") = 0 And _ InStr(1, oPara.Range.Text, "(capara)") = 0 Then oPara.Range.InsertBefore "(main) " End If End If If oPara.Range.Font.Size = 8 Then If InStr(1, oPara.Range.Text, "(intro)") = 0 And _ InStr(1, oPara.Range.Text, "(main)") = 0 And _ InStr(1, oPara.Range.Text, "(capara)") = 0 Then oPara.Range.InsertBefore "(capara) " oPara.Range.InsertParagraphBefore oPara.Range.InsertBefore "(start) " End If End If If oPara.Range.Font.Size = 10 Then If InStr(1, oPara.Range.Text, "(intro)") = 0 And _ InStr(1, oPara.Range.Text, "(main)") = 0 And _ InStr(1, oPara.Range.Text, "(capara)") = 0 Then oPara.Range.InsertBefore "(intro) " End If End If Next oPara 'Con esto borramos el primer espacio del documento (evitamos una línea demás en los edictos) Selection.HomeKey Unit:=wdStory Selection.MoveDown Unit:=wdLine, Count:=2 Selection.MoveRight Unit:=wdCharacter, Count:=8 Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace Selection.TypeBackspace 'Crea el .txt para ser importado a Tera ChangeFileOpenDirectory "C:\edictos\" ActiveDocument.SaveAs FileName:="C:\edictos\Edictos.txt", FileFormat:= _ wdFormatText, AddToRecentFiles:=True, _ WritePassword:="", EmbedTrueTypeFonts:=False, _ SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _ False, Encoding:=1252, InsertLineBreaks:=False, AllowSubstitutions:=False, _ LineEnding:=wdCRLF MsgBox "Proceso completado", 0, "Yay!" ActiveDocument.Close End Sub
As you see, it ends up saving a .txt document with the tags.
NOW... the issue is that the tags wont work anymore in the new system, and I need to wrap the paragraph in XML Tags. I tried to do something like for styles:
If oPara.Range.Style = "LW" Then If InStr(1, oPara.Range.Text, "<intro>") = 0 And _ InStr(1, oPara.Range.Text, "<main>") = 0 And _ InStr(1, oPara.Range.Text, "<capara>") = 0 Then oPara.Range.InsertAfter "</main> " oPara.Range.InsertBefore "<main> " End If End If
But it just would add the two tags before the paragraphs!!! Is there anyway to wrap the paragraph in XML tags, following my logic? Somebody help please!! Thank you!! :/
Saturday, March 1, 2014 12:49 AM
Answers
-
Hi,
Sorry for my delay.
I am afraid that this is not the proper forum for this issue, and I found that you have posted it in dedicated forum.
I would suggest you focus on that thread to get more dedicated support.
Thanks for your understanding.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by Cor Ligthert Monday, March 3, 2014 7:23 AM
- Marked as answer by Carl Cai Friday, March 7, 2014 7:18 AM
Monday, March 3, 2014 5:39 AM
All replies
-
Hi,
Sorry for my delay.
I am afraid that this is not the proper forum for this issue, and I found that you have posted it in dedicated forum.
I would suggest you focus on that thread to get more dedicated support.
Thanks for your understanding.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by Cor Ligthert Monday, March 3, 2014 7:23 AM
- Marked as answer by Carl Cai Friday, March 7, 2014 7:18 AM
Monday, March 3, 2014 5:39 AM -
You are right. Sorry and thank you.Monday, March 3, 2014 2:26 PM