Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default search facility

Hi Everyone.
Ive got some code below from some helpful chap on this
forum which i use to search through a whole range of
files in a folder, the problem is that it takes rather a
long time with it opening everysingle file.

Is there any way for it to do the same thing but with out
opening each file?

Simple instructions would be preferable, even better if
it can be a quick ammendment to the code below.

Thankyou for your help.


Set basebook = ThisWorkbook
rnum = 1
Do While FNames < ""
If Left(FNames, 1) = "0" Then
Set mybook = Workbooks.Open(FNames)
Range("A65000").End(xlUp).Select
n = ActiveCell.Row
Set sourceRange = mybook.Worksheets(1).Range
_ ("a1", "p" & n)
a = sourceRange.Rows.Count
Set destrange = basebook.Worksheets(1).Cells
_ (rnum, 1)
sourceRange.Copy destrange
rnum = rnum + a
mybook.Close False
End If
FNames = Dir()
Loop

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default search facility

I think that as your examine the contents dynamically, you won't improve it
much. If the cell you were retrieving was fixed, you could query each
workbook with ADO, but it would need to retrieve everything and then work
through.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"darren" wrote in message
...
Hi Everyone.
Ive got some code below from some helpful chap on this
forum which i use to search through a whole range of
files in a folder, the problem is that it takes rather a
long time with it opening everysingle file.

Is there any way for it to do the same thing but with out
opening each file?

Simple instructions would be preferable, even better if
it can be a quick ammendment to the code below.

Thankyou for your help.


Set basebook = ThisWorkbook
rnum = 1
Do While FNames < ""
If Left(FNames, 1) = "0" Then
Set mybook = Workbooks.Open(FNames)
Range("A65000").End(xlUp).Select
n = ActiveCell.Row
Set sourceRange = mybook.Worksheets(1).Range
_ ("a1", "p" & n)
a = sourceRange.Rows.Count
Set destrange = basebook.Worksheets(1).Cells
_ (rnum, 1)
sourceRange.Copy destrange
rnum = rnum + a
mybook.Close False
End If
FNames = Dir()
Loop



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default search facility

"Bob Phillips" wrote ...

If the cell you were retrieving was fixed, you could query each
workbook with ADO, but it would need to retrieve everything and then work
through.


Bob,
Rather than the cells being the problem, I see the worksheet name
being the problem. If mybook.Worksheets(1) always had the same name,
say Sheet1, the OP could use the following query:

SELECT * FROM [Sheet1$A1:P65536];

Or rather

INSERT INTO
[MyDestRange]
SELECT * FROM
[Excel 8.0;Database=C:\MySearchFolder\MyBook1.xls;].[Sheet1$A1:P65536];

for each source workbook. And if there weren't too many workbooks it
could be done in one hit:

INSERT INTO
[MyDestRange]
SELECT * FROM
[Excel 8.0;Database=C:\MySearchFolder\MyBook1.xls;].[Sheet1$A1:P65536]
UNION ALL
SELECT * FROM
[Excel 8.0;Database=C:\MySearchFolder\MyBook2.xls;].[Sheet1$A1:P65536]
UNION ALL
SELECT * FROM
[Excel 8.0;Database=C:\MySearchFolder\MyBook3.xls;].[Sheet1$A1:P65536]
ORDER BY
1 ASC, 2 DESC;

ADO would discard any blank rows below the used range i.e. wouldn't
get all 65536 rows unless they had been populated.

Without the consistent sheet names, I know of no reliable way of
getting the name of the first worksheet using ADO. Both ADOX's Tables
collection and ADODB OpenSchema (adSchemaTables) method's recordset
appear in order of table name and, not surprisingly, have no 'table
ordinal position' property.

Jamie.

--
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
List Box with lookup facility Col Excel Worksheet Functions 1 October 14th 08 01:49 AM
Is there a 'floating key/ legend' facility? Andrew at fourninety.com Excel Discussion (Misc queries) 2 June 22nd 07 11:48 AM
Spelling Facility Zygy New Users to Excel 2 December 11th 06 05:49 PM
how do i use LOTUS combine facility in Excel seawardr Excel Discussion (Misc queries) 3 October 22nd 06 10:23 PM
Set up an Ordering facility for a Buying Dept Stuart[_5_] Excel Programming 2 December 4th 03 09:20 PM


All times are GMT +1. The time now is 09:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"