J'utilise le code ci-dessous pour générer du code XML à partir de tables de fichiers Word.mot/VBA: Impossible de récupérer le texte mis en forme de la table
Sub exprt() Dim nofT, cnt, tag, btxt As Integer
Dim Rcnt As Long
Dim tit, pTyp, cValu As String
Dim dum As Range
Set a = ActiveDocument.Tables
nofT = ActiveDocument.Tables.Count
Set docold = ActiveDocument
For cnt = 5 To nofT
Selection.TypeText ("")
Selection.TypeParagraph
Selection.TypeText ("")
Selection.TypeParagraph
Set dum = ActiveDocument.Tables(cnt).Cell(2, 1).Range
dum.End = dum.End - 1
tit = dum.Text
tit = LTrim(Right(tit, (Len(tit) - InStr(tit, ":"))))
Selection.TypeText (Chr(9) + "<" + Chr(33) + "[CDATA[" + tit + "]]><" + Chr(47) + "title_text_1>")
Selection.TypeParagraph
Selection.TypeParagraph
Rcnt = a(cnt).Rows.Count
Set dum = ActiveDocument.Tables(cnt).Cell(3, 1).Range
dum.End = dum.End - 1
pTyp = dum.Text
pTyp = LTrim(Right(pTyp, (Len(pTyp) - InStr(pTyp, ":"))))
tag = 1
For btxt = 6 To Rcnt - 1
Set dum = ActiveDocument.Tables(cnt).Cell(btxt, 1).Range.FormattedText
dum.End = dum.End - 1
Selection.TypeText (Chr(9) + "<" + Chr(33) + "[CDATA[" + dum + "]]><" + Chr(47) + "body_text_" + LTrim(Str(tag)) + ">")
Selection.TypeParagraph
Selection.TypeParagraph
tag = tag + 1
Next
Set dum = docold.Tables(cnt).Cell(Rcnt, 1).Range
dum.End = dum.End - 1
Selection.TypeText (Chr(9) + "<" + Chr(33) + "[CDATA[" + dum + "]]><" + Chr(47) + "prompt_text_1>")
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText ("<" + Chr(47) + "data>")
Selection.TypeParagraph
Selection.Extend
Selection.HomeKey Unit:=wdStory
newTxt = ActiveDocument.ActiveWindow.Selection
Selection.Cut
Set dum = docold.Tables(cnt).Cell(1, 1).Range
dum.End = dum.End - 1
Call pub(dum.Text)
Next
End Sub
Sub pub(nme As String)
Dim FolderPath As String
Dim FileName As String
FolderPath = "c:/Chandru/"
FileName = nme & ".xml"
Documents.Add
Selection.Paste
Call bld
ActiveDocument.SaveAs FileName:=FolderPath & FileName, FileFormat:=wdFormatText
ActiveDocument.Close
End Sub
Problème: Je veux ajouter "< b> & </b>" pour le texte en gras, de même pour le texte en italique. Lorsque je récupère le contenu de la cellule du tableau, je ne reçois pas de texte formaté. Comment puis-je ajouter < b> & < i> pour gras & en italique respectivement ??