J'ai crée un fichier (trame) .doc dans lequel j'ai remplacé certains mots par "[PROD-total-C]", [PROD-libre-C]...
Je copie ce fichier sous un nouveau nom (.rtf).
Mon souhait serait d'ouvrir ce nouveau fichier (.doc ou .rtf) et
et remplacer les valeurs "[PROD-total-C]", [PROD-libre-C]...
par le contenu de variables issues de mon script vbs.
Celui-ci récupère l'espace disk (total, libre..) de plusieurs disks et lecteurs réseaux.
J'ai parcouru ce forum, exalead et MSDN.
Rien ne m'a inspiré.
Si quelqu'un d'entre-vous a une idée ou une orientation.
Merci.
jean-marc
J'utilise vbs pour ouvrir des .mdb, .txt ou .xls,mais là, c'est la première fois
que je suis confronté à word.
=======================================
mauvaise synthaxe:
Dim oWordApp
Set oWordApp = CreateObject("Word.Application")
Set oDoc = oWordApp.Documents.Open(FicOutput, 1)
'un process winword est ouvert, mais pas mon fichier
=======================================
Do While Not ObjTextStream.AtEndOfStream
strtmp = Split(objTextStream.ReadLine,".")
For i = 0 To UBound(strtmp)
strtmp = Replace(strtmp, "[PROD-total-C]", [PROD-total-C])
strtmp = Replace(strtmp, "[PROD-libre-C]", [PROD-libre-C])
strtmp = Replace(strtmp, "[PROD-total-D]", [PROD-total-D])
strtmp = Replace(strtmp, "[PROD-libre-D]", [PROD-libre-D])
Next
Loop
Set Word = CreateObject("Word.Application")
Word.DisplayAlerts = wdAlertsNone
Set Doc = Word.Documents.Open("i:\a.doc", True)
If Not Doc Is Nothing Then
Doc.Tables(1).Cell(2, 2).Range.Text = "=Prod-total-C"
Doc.Tables(1).Cell(2, 3).Range.Text = "=Prod-libre-C"
Doc.Tables(1).Cell(3, 2).Range.Text = "=Prod-total-D"
Doc.Tables(1).Cell(3, 3).Range.Text = "=Prod-libre-D"
Doc.Tables(1).Cell(4, 2).Range.Text = "=Prod-total-E"
Doc.Tables(1).Cell(4, 3).Range.Text = "=Prod-libre-E"
Doc.Tables(1).Cell(5, 2).Range.Text = "=Prod-total-F"
Doc.Tables(1).Cell(5, 3).Range.Text = "=Prod-libre-F"
Doc.Tables(1).Cell(6, 2).Range.Text = "=Prod-total-G"
Doc.Tables(1).Cell(6, 3).Range.Text = "=Prod-libre-G"
Doc.Save
MsgBox "Terminé", vbInformation
End If
Word.Quit
pour le mettre au point, a moins d'avoir VB6 sous la main, utilise l'environnement VBA (Alt + F11 dans Word)
en tatonnant un peu , tu arriveras a tes fins
Set Word = CreateObject("Word.Application")
Word.DisplayAlerts = wdAlertsNone
Set Doc = Word.Documents.Open("i:\a.doc", True)
If Not Doc Is Nothing Then
Doc.Content = Replace(Doc.Content, "[PROD-total-C]", TotalC)
Doc.Save
MsgBox "Terminé", vbInformation
End If
Word.Quit
Merci Renfield,
Je vais testé. Je sais que TextStream n'est pas la bonne synthaxe,
mais je ne connais pas les fonctions VBA de Word.
Je vais regarder l'help de Word.
Vous n’avez pas trouvé la réponse que vous recherchez ?