Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1283 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Traitement d'une fonction Ping avec une liste de PC ds un fichier exl

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Traitement d'une fonction Ping avec une liste de PC ds un fichier exl

n°1550138
PetitNewby
Posté le 26-04-2007 à 16:41:09  profilanswer
 

Bonjour je vousdrais traiter et ecrire dans un fichier excel avec mon script VBS
 
voici mon script
 
Set objFSO = CreateObject("Scripting.FileSystemObject" )
Set objFile = objFSO.OpenTextFile("Liste.txt",1)
Do Until ObjFile.AtEndOfStream
        StrComputer = objFile.ReadLine
        Ping()
Loop
ObjFile.Close
 
 
Function PING()
Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2" )
Set colPings = objWMIService.ExecQuery _
    ("Select * From Win32_PingStatus where Address = '" & strComputer &"'" )
 
For Each objStatus in colPings
    If IsNull(objStatus.StatusCode) _
        or objStatus.StatusCode<>0 Then
        Msgbox strComputer & "Computer did not respond."
    Else
        Msgbox strComputer & "Computer responded."
    End If
Next
End Function
 
 
 
Je souhaiterais a la place de travailler dans un fichier TXT travailler dans un tableau Excel
 
Dans un premier temps
le programme utilise les information de la premiere colonne ' lecture'
et dans un 2eme tps il faudrais qu'il ecrive en face de chaque Pc si le ping est OK ou non donc 'ecriture'
mais je ne sais pas par ou m'orienter pour traiter un tableau excel
 
bien a vous et merci pour votre aide
 

mood
Publicité
Posté le 26-04-2007 à 16:41:09  profilanswer
 

n°1550607
Macromorph
Tu l'as vu ?
Posté le 27-04-2007 à 15:00:10  profilanswer
 
n°1555943
PetitNewby
Posté le 06-05-2007 à 11:46:54  profilanswer
 

Set objExcel = CreateObject("Excel.Application" )
Set objWorkbook = objExcel.Workbooks.Open("C:\liste.xls" )
 
intRow = 1
 
'Lecture de la colonne 1
Do Until objExcel.Cells(intRow,1).Value = ""
    StrComputer = objExcel.Cells(intRow, 1).Value
    PING()
    intRow = intRow + 1
Loop
 
objExcel.Quit
 
'Fonction PING
Function PING()
Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2" )
Set colPings = objWMIService.ExecQuery _
    ("Select * From Win32_PingStatus where Address = '" & strComputer &"'" )
 
 
For Each objStatus in colPings
    If IsNull(objStatus.StatusCode) _
        or objStatus.StatusCode<>0 Then
        objExcel.Workbooks.Add("C:\liste.xls" )
        msgbox intRow & "NOK" & strComputer
        objExcel.Cells(intRow, 2).Value = "NOK"
    Else
        objExcel.Workbooks.Add("C:\liste.xls" )
        msgbox intRow & "OK" & strComputer
        objExcel.Cells(intRow, 2).Value = "OK"
    End If
Next
End Function
 
 
 
Il me reste un ptit probleme comment agir sur le meme fichier xls  
mon prog me retourne l'enregistrement de d'autre fichier xls
etant donne qui utilise le fichier liste dans la premier boucle  
quelqu'un a une astuce pr se probleme  
sachant que je ne ve pas utilise un autre fichier excel


Message édité par PetitNewby le 06-05-2007 à 11:51:23
n°1583196
jim150181
Posté le 06-07-2007 à 14:06:52  profilanswer
 

Voici une solution, c'est pas très élègant, mais ça marche avec 1 seul fichier !
Vérifie que ton fichier est bien fermé avant, car sinon il y aura un prob de fichier en lecture seul.
Je l'ai testé et ça marche
Bonne journée (répond moi)

 

msgbox "Cliquez pour débuter les pings"
Set objExcel = CreateObject("Excel.Application" )
Set objWorkbook = objExcel.Workbooks.Open("C:\Documents and Settings\jmour\Mes documents\liste.xls" )
intRow = 1
 
'Lecture de la colonne 1
Do Until objExcel.Cells(intRow,1).Value = ""
    StrComputer = objExcel.Cells(intRow, 1).Value
    objworkbook.close
    PING()
    Set objworkbook = objExcel.Workbooks.Open("C:\liste.xls" )
    intRow = intRow + 1
Loop
objworkbook.close
msgbox "Pings terminés"
objExcel.Quit
 
'Fonction PING
Function PING()
Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2" )
Set colPings = objWMIService.ExecQuery _
    ("Select * From Win32_PingStatus where Address = '" & strComputer &"'" )
 
 
For Each objStatus in colPings
    If IsNull(objStatus.StatusCode) _
        or objStatus.StatusCode<>0 Then
        set objworkbook1 = objExcel.Workbooks.Open("C:\liste.xls" )
        'msgbox intRow & " NOK " & strComputer
 objExcel.Cells(intRow, 3).Value = ""
        objExcel.Cells(intRow, 4).Value = "Ping Non OK"
 objworkbook1.save
 objworkbook1.close
    Else
        set objworkbook2 = objExcel.Workbooks.Open("C:\liste.xls" )
        'msgbox intRow & " OK " & strComputer
        objExcel.Cells(intRow, 3).Value = "Ping OK"
 objExcel.Cells(intRow, 4).Value = ""
 objworkbook2.save
 objworkbook2.close
    End If
Next
End Function


Message édité par jim150181 le 06-07-2007 à 14:09:15
n°2211225
stevefkd
Posté le 21-11-2013 à 13:52:26  profilanswer
 

Bonjour, j'ai testé la solution : elle fonctionne tres bien, mais sous excel 2007 , apparement , apres chaque ping, excel demande 'Voulez vous enregistrer les modifs apportées à liste.xls".
Y'a t il un moyen d'eviter cette demande, j'ai plus de 600 adresses à 'Pinger' ?


---------------
Plus j'étudie, plus j'apprends, plus j'apprends, plus j'ai concience des mes lacunes.
n°2211229
stevefkd
Posté le 21-11-2013 à 14:19:02  profilanswer
 

Petite precision : j'utilise un fichier source et un fichier destination different car sinon excel 2007 finit par bugger.


---------------
Plus j'étudie, plus j'apprends, plus j'apprends, plus j'ai concience des mes lacunes.
n°2211232
stevefkd
Posté le 21-11-2013 à 14:31:32  profilanswer
 

Laissez tomber : la solution fonctionne tres bien quand on n'essaye pas de la bidouiller ( comme je l'ai fait, je suis une bille en vbs )  
Pardon,
Mes excuses à ceux qui ont cherché.


---------------
Plus j'étudie, plus j'apprends, plus j'apprends, plus j'ai concience des mes lacunes.

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Traitement d'une fonction Ping avec une liste de PC ds un fichier exl

 

Sujets relatifs
[Excel-VBA]Fonction IF je pète un cablePHP et Active Directory (fonction ldap_search) [résolu]
Bien structurer un fichier XMLproblème: Pagination moteur de recherche
recherche fonction HTML TO XMLimport gros fichier SQL dans Mysql
Equivalent de "transférer à" via la fonction mail() ?Impression avec Excel dans un fichier externe
convertir fichier mdb en xlstraitement d'un fichier texte.
Plus de sujets relatifs à : Traitement d'une fonction Ping avec une liste de PC ds un fichier exl


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR