Login | |
|
 |
RE: Excel and vbs - 12/19/2007 1:13:52 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
For some reason it won't let me download from those links. Regardless, I have created a test xls that mirrors the image that you posted earlier. I think we need a quick reset. What is the goal of this code? What information are you trying to get out of the xls and why? What criteria indicate a row that you want to get the info from?
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Excel and vbs - 12/19/2007 2:18:10 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
Try this: Set ObjFSO = CreateObject("Scripting.FileSystemObject") Const ForWriting = 2 Set objFile = objFSO.OpenTextFile("c:test.txt", ForWriting, True) Dim ex, I, ID Set ex = CreateObject("Excel.Application") ex.Workbooks.Open "C:\Log1.xls" 'Open file bGetData = False With ex.ActiveSheet 'Range = ex.ActiveSheet.Range("A:B:E").Select For I = 1 To ex.ActiveSheet.UsedRange.Rows.Count If (ex.ActiveSheet.Range("B" & I).Value = "APOSTOLIDIS" And ex.ActiveSheet.Range("C" & I).Value = "FOIVOS" And ex.ActiveSheet.Range("I" & I).Value = "6945757419") Or (bGetData And ex.ActiveSheet.Range("B" & I).Value = "") Then ID = ex.ActiveSheet.Range("C" & I).Value ID2 = ex.ActiveSheet.Range("D" & I).Value 'objfile.WriteLine "TEst : " & ID & " Test 2 : " & ID2 bGetData = True Else bGetData = False End if Next End With objFile.Close ex.Quit WScript.Quit
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Excel and vbs - 12/19/2007 2:51:02 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
Basicly bGetData is a state variable. So whenever we find the person that we are interested in we set it to true. Then as long as the line has the user name we want OR the state vriable is true and there isn't a user name on the line, then we collect the data. The other important line is in the else clause. So if the line has user name information but it isn't the right user, we set the state variable to false. That way we don't collect data from other users.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Excel and vbs - 12/19/2007 3:26:03 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
Set ObjFSO = CreateObject("Scripting.FileSystemObject") Const ForWriting = 2 Set objFile = objFSO.OpenTextFile("test.txt", ForWriting, True) Dim ex, I, ID Set ex = CreateObject("Excel.Application") ex.Workbooks.Open "C:\Log1.xls" 'Open file bGetData = False bUserNotFound = True With ex.ActiveSheet 'Range = ex.ActiveSheet.Range("A:B:E").Select For I = 1 To ex.ActiveSheet.UsedRange.Rows.Count If (ex.ActiveSheet.Range("B" & I).Value = "XELIOTIa" And ex.ActiveSheet.Range("C" & I).Value = "KATERINA" And ex.ActiveSheet.Range("I" & I).Value = "") Or (bGetData And ex.ActiveSheet.Range("B" & I).Value = "") Then IDD = ex.ActiveSheet.Range("D" & I).Value IDE = ex.ActiveSheet.Range("E" & I).Value IDF = ex.ActiveSheet.Range("F" & I).Value IDG = ex.ActiveSheet.Range("G" & I).Value IDH = ex.ActiveSheet.Range("H" & I).Value objfile.WriteLine "Course : " & IDD & " Absences' Limit : " & IDE & " Total Absences : " & IDF & " Excused Absences : " & IDG & " Unexcused Absences : " & IDH bGetData = True bUserNotFound = False Else bGetData = False End if Next End With If bUserNotFound Then objfile.WriteLine " Data Not Found " End If objFile.Close ex.Quit WScript.Quit
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|