Usuário com melhor resposta
Monitora Célula Excel

Pergunta
-
Amigos,
Preciso de ajuda para finalizar uma rotina vbs que monitora se uma determinada célula de uma planilha foi preenchida.
Exemplo: se a célula B10 foi preenchida chamasse a bat 1, se essa mesma célula continuar vazia se chamar a bat 2.
Podem ajudar?
Abçs
FOliveira
Respostas
-
Ola FOliveira segue explicação e script atualizado.
' ------------------------------------------------------' Option Explicit Dim oShell, objExcel, objSpread, intRow, strSheet, strValue, WshShell ' -------------------------------------------------------------' ' -------------------------------------------------------------' Set oShell = CreateObject("WScript.Shell") Set WshShell = WScript.CreateObject("WScript.Shell") strSheet = oShell.CurrentDirectory & "\Log.xls" ' Open the Excel spreadsheet Set objExcel = CreateObject("Excel.Application") Set objSpread = objExcel.Workbooks.Open(strSheet) intRow = 1 'Row 1 often contains headings ' Here is the 'DO...Loop' that cycles through the cells ' Note intRow, x must correspond to the column in strSheet Do Until objExcel.Cells(intRow,1).Value = "" strValue = Trim(objExcel.Cells(intRow, 1).Value) MsgBox(strValue) If strValue = "Timeout" Then WshShell.Run ("C:\Bat_1.bat") ElseIf strValue = "NonTimeout" Then WshShell.Run ("C:\Bat_2.bat") End If intRow = intRow + 1 Loop objExcel.Quit
Quanto ao Excel segue imagem
Abraços espero ter ajudado
Edson Matias Fagundes Junior - (Nioks)
MCP, MCTS: 2008, MCTS:MBS
Se a resposta for valida por favor vote como útil.- Sugerido como Resposta Edson Matias Fagundes Junior quarta-feira, 24 de agosto de 2011 12:24
- Marcado como Resposta Richard Juhasz quinta-feira, 1 de setembro de 2011 20:14
-
FOliveira,
Conseguiu testar lhe atendeu o Scritp.
Abraços
Edson Matias Fagundes Junior - (Nioks)
MCP, MCTS: 2008, MCTS:MBS
Se a resposta for valida por favor vote como útil.- Marcado como Resposta Foliveira quinta-feira, 8 de setembro de 2011 21:12
Todas as Respostas
-
-
FOliveira,
Você deve incluir na linha 1 o numero 1 e nas celulas abaixo desta voce deve prencher algo como executar1 e executar2.
' ------------------------------------------------------' Option Explicit Dim oShell, objExcel, objSpread, intRow, strSheet, strValue, WshShell ' -------------------------------------------------------------' ' -------------------------------------------------------------' Set oShell = CreateObject("WScript.Shell") Set WshShell = WScript.CreateObject("WScript.Shell") strSheet = oShell.CurrentDirectory & "\Arquivo.xls" ' Open the Excel spreadsheet Set objExcel = CreateObject("Excel.Application") Set objSpread = objExcel.Workbooks.Open(strSheet) intRow = 1 'Row 1 often contains headings ' Here is the 'DO...Loop' that cycles through the cells ' Note intRow, x must correspond to the column in strSheet Do Until objExcel.Cells(intRow,1).Value = " " strValue = Trim(objExcel.Cells(intRow, 1).Value) MsgBox(strValue) If strValue = "Valorpara o Script1" Then WshShell.Run ("c:\arquivo1.bat") Else WshShell.Run ("c:\arquivo2.bat") End If intRow = intRow + 1 Loop objExcel.Quit
Alguns dados devem ser alterados antes no vbs ok.Boa noite a todos... ultima threads do dia... rsrs
Abraços
Edson Matias Fagundes Junior - (Nioks)
MCP, MCTS: 2008, MCTS:MBS
Se a resposta for valida por favor vote como útil. -
Edson,
Obrigado pelo retorno!
Não entendi a parte:
"Você deve incluir na linha 1 o numero 1 e nas celulas abaixo desta voce deve prencher algo como executar1 e executar2"
Usando o vbs abaixo, fiz a primeira execução, mas as duas bats foram chamadas quando encontrou a string 'TIMEOUT' na 1ª célula do arquivo excel Log.xls. Pode ajudar?
' ------------------------------------------------------'
Option Explicit
Dim oShell, objExcel, objSpread, intRow, strSheet, strValue, WshShell
' -------------------------------------------------------------'
' -------------------------------------------------------------'
Set oShell = CreateObject("WScript.Shell")
Set WshShell = WScript.CreateObject("WScript.Shell")
strSheet = oShell.CurrentDirectory & "\Log.xls"
' Open the Excel spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
intRow = 1 'Row 1 often contains headings
' Here is the 'DO...Loop' that cycles through the cells
' Note intRow, x must correspond to the column in strSheet
Do Until objExcel.Cells(intRow,1).Value = " "
strValue = Trim(objExcel.Cells(intRow, 1).Value)
MsgBox(strValue)
If strValue = "TIMEOUT" Then
WshShell.Run ("I:\Bat_1.bat")
Else
WshShell.Run ("I:\Bat_2.bat")
End If
-
Ola FOliveira segue explicação e script atualizado.
' ------------------------------------------------------' Option Explicit Dim oShell, objExcel, objSpread, intRow, strSheet, strValue, WshShell ' -------------------------------------------------------------' ' -------------------------------------------------------------' Set oShell = CreateObject("WScript.Shell") Set WshShell = WScript.CreateObject("WScript.Shell") strSheet = oShell.CurrentDirectory & "\Log.xls" ' Open the Excel spreadsheet Set objExcel = CreateObject("Excel.Application") Set objSpread = objExcel.Workbooks.Open(strSheet) intRow = 1 'Row 1 often contains headings ' Here is the 'DO...Loop' that cycles through the cells ' Note intRow, x must correspond to the column in strSheet Do Until objExcel.Cells(intRow,1).Value = "" strValue = Trim(objExcel.Cells(intRow, 1).Value) MsgBox(strValue) If strValue = "Timeout" Then WshShell.Run ("C:\Bat_1.bat") ElseIf strValue = "NonTimeout" Then WshShell.Run ("C:\Bat_2.bat") End If intRow = intRow + 1 Loop objExcel.Quit
Quanto ao Excel segue imagem
Abraços espero ter ajudado
Edson Matias Fagundes Junior - (Nioks)
MCP, MCTS: 2008, MCTS:MBS
Se a resposta for valida por favor vote como útil.- Sugerido como Resposta Edson Matias Fagundes Junior quarta-feira, 24 de agosto de 2011 12:24
- Marcado como Resposta Richard Juhasz quinta-feira, 1 de setembro de 2011 20:14
-
FOliveira,
Conseguiu testar lhe atendeu o Scritp.
Abraços
Edson Matias Fagundes Junior - (Nioks)
MCP, MCTS: 2008, MCTS:MBS
Se a resposta for valida por favor vote como útil.- Marcado como Resposta Foliveira quinta-feira, 8 de setembro de 2011 21:12
-