En vbs, problème de modif de fichier Word

cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 - 6 avril 2006 à 22:08
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 - 7 avril 2006 à 20:43
Bonjour à tous....

Suite à un précédent post, Renfield m'a bien dépanné pour:
- avec un .vbs comment modifier un tableau dans un .doc;
problème résolu.

Sur XP Pro, ayant une version incomplète (at home), je n'ai pas accès à l'aide VBA/Word (alt+F11).

Mon nouveau souci est: comment modifier un texte prcisé par une variable dans mon .doc ???

Ci-dessous, mon fichier original (incomplet car je récupère des données de plusieurs servers).




DATE :[jj/mm/aa]

















ESPACE LIBRE SIBL-DB-PROD





Partition

,
Espace Total

,
Espace Libre

,
Commentaires

,
----

C : (SYSTEM)

,

,

,
alerte

,
----

D : (SWAP)

,
,

,



Avec le script ci-dessous, j'arrive donc à renseigner mon tableau.
Deux questions:
1) Comment modifier le texte [jj/mm/aa] par une variable de mon script ??? Ce texte figure plusieurs
fois dans mon .doc

2) Dans mon tableau,
par ex: Doc.Tables(1).Cell(2, 4).Range.Text = "alerte", comment colorier cette cellule

Merci.
jean-marc
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Fic = "d:\ControleRICOH\test.doc"
Call ShowFreePourcent()
'MsgBox ShowFreePourcent
Set fso = Nothing
Set Word = Nothing
Set Doc = Nothing
MsgBox "script test terminé !!!"


Function ShowFreePourcent()


Dim fso, dc
Set fso = CreateObject("Scripting.FileSystemObject")
Set dc = fso.Drives 'permet de parcourir les disks
For Each d in dc
Select Case d.DriveLetter 'selection en fonction de la lettre du lecteur


Case "C"
PROD_total_C = FormatNumber(d.TotalSize/1024/1024/1024, 2) & " Go"
PROD_libre_C = FormatNumber(d.AvailableSpace/1024/1024/1024, 2) & " Go"


Case "D"
PROD_total_D = FormatNumber(d.TotalSize/1024/1024/1024, 2) & " Go"
PROD_libre_D = FormatNumber(d.AvailableSpace/1024/1024/1024, 2) & " Go"

Case Else
End Select

Next


Dim Word, Doc
Set Word = CreateObject("Word.Application")
Word.DisplayAlerts = wdAlertsNone


Set Doc = Word.Documents.Open(Fic, 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 = "ca marche !!!" 'Prod_libre_G
Doc.Tables(4).Cell(2, 2).Range.Text = Prod_total_C
Doc.Tables(4).Cell(2, 3).Range.Text = Prod_libre_C
Doc.Tables(4).Cell(3, 2).Range.Text = Prod_total_D
Doc.Tables(4).Cell(3, 3).Range.Text = Prod_libre_D



Doc.Save
Doc.Close
Word.Quit
End If


End Function

2 réponses

titsuisse Messages postés 27 Date d'inscription mardi 4 janvier 2005 Statut Membre Dernière intervention 7 avril 2006
7 avril 2006 à 11:42
Pour colorier ta cellule en rouge

Doc.Tables(1).Cell(2, 4).select
With Selection.Cells.Shading
.BackgroundPatternColor = wdColorRed
End With

Si ça marche pas essaie

Doc.Tables(1).cell(2,4).range.select
With Selection.Interior
.ColorIndex = 3
End With
0
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
7 avril 2006 à 20:43
Bonsoir,

Merci " 416618 titsuisse"
J'ai testé les 2 propositions.

1) erreur objet requis selection
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(2, 3).select
With Selection.Cells.Shading
.BackgroundPatternColor = wdColorRed
End With

Doc.Tables(1).Cell(3, 2).Range.Text = Prod_total_D

2) erreur objet requis selection
Doc.Tables(1).Cell(2, 3).Range.Text = Prod_libre_C
Doc.Tables(1).cell(2,3).range.select
With Selection.Interior
.ColorIndex = 3
End With

Merci quand même.

jean-marc
0
Rejoignez-nous