Get data from Excel
Moderators: Dorian (MJT support), JRL
Find Worked
Yes, when I am in the spreadsheet I can use find with no issues. I can search for what I am looking for and other data as well. I can read all of the cells.
I have deleted columns and tried it with no sucess.
It has to be something with the sheet, but what? I tried exporting it to a text file and saw a non ASCII Character in the text file so I deleted that column, saved the file and tried again. Still with no luck.
I have deleted columns and tried it with no sucess.
It has to be something with the sheet, but what? I tried exporting it to a text file and saw a non ASCII Character in the text file so I deleted that column, saved the file and tried again. Still with no luck.
Make the problem as small as possible.
Try deleting all rows except the row containing the cell you are looking for and any rows it references.
Then further reduce your spreadsheet by deleting all unrelated columns.
If you are still seeing the problem there should at least be fewer variables to contend with.
Gale
Then further reduce your spreadsheet by deleting all unrelated columns.
If you are still seeing the problem there should at least be fewer variables to contend with.
Gale
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Received your file. The code you posted works fine against your file without any errors. I tried it with various data and it always returned the correct cell. I'm using Vista and Excel 2007.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Excel install missing dll?
Since it is not the script or the file it must be site related.
Read this:
http://answers.yahoo.com/question/index ... 808AA57h9j
Gale
Read this:
http://answers.yahoo.com/question/index ... 808AA57h9j
Gale
Excel Error
Well I am offically at a loss.
It works for Marcus, so the script is fine and the file must be fine.
It works for me on other files, which tells me that it is the file not the script.
It does not work on any machine I tested it on. Vista and XP both with Office 2007.
Thanks for all of your help.
It works for Marcus, so the script is fine and the file must be fine.
It works for me on other files, which tells me that it is the file not the script.
It does not work on any machine I tested it on. Vista and XP both with Office 2007.
Thanks for all of your help.
Combination of file and machine
All of your machines appear to have something in common that is different than the machine Marcus used because the script and the file was the same everywhere.
The link I provided says certain Excel dll's must exist and be properly registered depending on which Excel objects are needed. The dll for at least one of those objects is not properly registered on any of your machines but is on Marcus's. But which object and therefore which dll?
Gale
The link I provided says certain Excel dll's must exist and be properly registered depending on which Excel objects are needed. The dll for at least one of those objects is not properly registered on any of your machines but is on Marcus's. But which object and therefore which dll?
Gale
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Excel Security
It makes perfect sense, however, I am an administrator, and I sent the test file to Marcus, whatever security should be the same or I would think. He was able to use the command I was not.
Please keep in mind that I can run the script on another file so it is not the machine and the security of the file makes perfect sense. But then again I can access and read any cell (I have not tried to write a cell) It gets more puzzeling
Please keep in mind that I can run the script on another file so it is not the machine and the security of the file makes perfect sense. But then again I can access and read any cell (I have not tried to write a cell) It gets more puzzeling
Maybe the dll needed depends on the data
Perhaps it is the machine if the particular data type of data contained in the cell range. What is different about the data in the files where the script works.
Here is a good link about the Find method:
http://www.microsoft.com/technet/script ... y0118.mspx
Gale
Here is a good link about the Find method:
http://www.microsoft.com/technet/script ... y0118.mspx
Gale
Kpassaur,
You mentioned that you did a saveas:
OR... have you tried collecting your data using the dbquery> function? It can quickly retrieve all the data from a record (row) in an Excel workbook. If you need to know the row number, you could create a "Row Number" column that contains sequential numbers that match the row numbers. The "Row Number" column information could then be part of the retrieved record.
Try something like this. Step through it in the editor and check the variables that are created.
You could also use DBQuery> to poll a cell in a similar fashion to the excellent original answer posted in this thread by ainterne. Again you need to create a "Row Number" column in your excel worksheet that contains sequential numbers that match the row numbers.
You mentioned that you did a saveas:
Did you or can you do a copy of the data and then paste it into a completely different excel workbook and save that. This of course does not copy formulas, cell types, macros, etc. But if your file is just a data file it might be worth trying.Kpassaur wrote: I thought maybe it was corrupt so I opened it, saved it with a different name etc with the same results.
OR... have you tried collecting your data using the dbquery> function? It can quickly retrieve all the data from a record (row) in an Excel workbook. If you need to know the row number, you could create a "Row Number" column that contains sequential numbers that match the row numbers. The "Row Number" column information could then be part of the retrieved record.
Try something like this. Step through it in the editor and check the variables that are created.
Code: Select all
//You would set these variables as required
Let>FileName=ExcelFile.xlsx
Let>DateColumnName=Date
Let>DateToFind=01/31/2009
//This will provide the entire record for every %DateToFind% in the %DateColumnName% column.
Let>connStr1=Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%Filename%;Extended Properties=Excel 8.0;
DBConnect>connStr1,dbH1
Let>SQL1=select * from [Sheet1$] where [%DateColumnName%] = #%DateToFind%#
DBQuery>dbH1,SQL1,rsSheet1,nR,nF
Code: Select all
//You would set these variables as required
Let>FileName=C:\Book1.xls
Let>TempFileName=%temp_Dir%TempExcelFile.xls
//Leave These varaibles alone
Let>CF_OverWrite=1
Let>OldCellData=
Let>NewCellData=
Label>Start
//Retrieve the info from a copy of the file to prevent access violations
CopyFile>%FileName%,%TempFileName%
Let>connStr1=Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%TempFileName%;Extended Properties=Excel 8.0;
DBConnect>connStr1,dbH1
//This will collect all columns from sheet 1, row number 5
Let>SQL1=select * from [Sheet1$] where [Row Number] = 5
DBQuery>dbH1,SQL1,rsSheet1,nR,nF
DBClose>dbH1
//From row five lets poll column number 3
//Let the value of variable NewCellData hold the contents
//of the cell at row 5 column 3
Let>NewCellData=%rsSheet1_1_3%
//First pass Let OldCellData = NewCellData
If>OldCellData=
Let>OldCellData=%NewCellData%
Wait>5
Goto>Start
ELSE
//IF>%OldCellData%=%NewCellData% nothing has changed, go back to Start
//and check the cell again.
IF>%OldCellData%=%NewCellData%
Wait>5
Goto>Start
Else
//IF>%OldCellData%<>%NewCellData% then the cell has changed. Write the new
//contents to a file, reset OldCellData to the new contents,
//and go back and check the cell again.
WriteLn>%temp_dir%CellDataRecord.txt,wres,%NewCellData%
Let>OldCellData=%NewCellData%
Wait>5
Goto>Start
EndIF
EndIF
Save As
I did a save as, a fix corrupt file, exported data into a csv file and opened and saved the csv file all with no sucess.
I have tried the code on three different spreadsheets and it works on all of them just not the data in this sheet.
To top it off it only not works for me, it does for Marcus.
I have tried the code on three different spreadsheets and it works on all of them just not the data in this sheet.
To top it off it only not works for me, it does for Marcus.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Keith,
Have you tried recording a Find operation in this spreadsheet? I.e. open the spreadsheet, go to macros, record macro, then manually do the Find, then stop recording and then go and look at the VBA produced by the macro recorder. Try and run it.
Have you tried recording a Find operation in this spreadsheet? I.e. open the spreadsheet, go to macros, record macro, then manually do the Find, then stop recording and then go and look at the VBA produced by the macro recorder. Try and run it.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
I don't know if this helps any, but I ran the VB code for the find feature that Marcus shared. The first couple of time I also got an error.....Then I realized that while trying to step through the scrip I had had not completely finished stepping through the whole script a couple of times and had just stopped....
What this had done is leave the Excel spreadsheet open a few times and I could see this via taskmgr... Without shutting the old open versions the script didn't really work properly. So I closed them all and everything started working.
Just to make sure that I didn't have any open Excel sessions running I added an little Vb script that Marcus shared with me sometime ago.
VBSTART
Function ftps (pgm)
dim wmi, sQuery, processes, process
set wmi = getobject("winmgmts:")
sQuery = "select * from win32_process where name='" & pgm & "'"
set processes = wmi.execquery(sQuery)
for each process in processes
process.terminate
next
End Function
VBEND
VBRun>ftps,Excel.exe
This ensures that all my Excel sheets are closed down before I run the script......
Be careful though because as I have it above it closes ALL Excel spreadsheets regardless..
For me the find function works really well and is a useful addition.
I was just thinking that you might have some open copies and not be aware......if not, then please ignore...
Thanks...Phil.
What this had done is leave the Excel spreadsheet open a few times and I could see this via taskmgr... Without shutting the old open versions the script didn't really work properly. So I closed them all and everything started working.
Just to make sure that I didn't have any open Excel sessions running I added an little Vb script that Marcus shared with me sometime ago.
VBSTART
Function ftps (pgm)
dim wmi, sQuery, processes, process
set wmi = getobject("winmgmts:")
sQuery = "select * from win32_process where name='" & pgm & "'"
set processes = wmi.execquery(sQuery)
for each process in processes
process.terminate
next
End Function
VBEND
VBRun>ftps,Excel.exe
This ensures that all my Excel sheets are closed down before I run the script......
Be careful though because as I have it above it closes ALL Excel spreadsheets regardless..
For me the find function works really well and is a useful addition.
I was just thinking that you might have some open copies and not be aware......if not, then please ignore...
Thanks...Phil.
Phil.......
FindCell using VBScript and MS with Excel
Okay,
I know what the difficulty is but don't know how to correct it.
When I use this
VBEval>FindCell("%xlsheetname%","%company%"),cell
And there is a match it returns the row and column and works flawlessly
otherwise it returns:
Microsoft VBScript runtime error :424
Object required: 'theCell'
Line 37, Column 0
Line 37 in my script is
FindCell = CStr(theCell.Row) & ":" & CStr(theCell.Column)
Does anyone know what needs to be changed so that it does not return this but something that will allow the script to continue to run and the return value set to something that can be read as not found such as 0:0
I know what the difficulty is but don't know how to correct it.
When I use this
VBEval>FindCell("%xlsheetname%","%company%"),cell
And there is a match it returns the row and column and works flawlessly
otherwise it returns:
Microsoft VBScript runtime error :424
Object required: 'theCell'
Line 37, Column 0
Line 37 in my script is
FindCell = CStr(theCell.Row) & ":" & CStr(theCell.Column)
Does anyone know what needs to be changed so that it does not return this but something that will allow the script to continue to run and the return value set to something that can be read as not found such as 0:0
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Here's a modification to the function to avoid this:
Code: Select all
Function FindCell(Sheet,Data)
Dim theCell
Dim xlValues
xlValues = -4163
Dim xlSheet
Set xlSheet = xlBook.Worksheets(Sheet)
xlSheet.Range("A1").Select
Set theCell = xlSheet.Cells.Find(Data, xlApp.ActiveCell, xlValues)
if Not theCell is Nothing then
FindCell = CStr(theCell.Row) & ":" & CStr(theCell.Column)
else
FindCell = ""
End if
End Function
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?