PC Review


Reply
Thread Tools Rate Thread

Check if a sheet exists in a file, without opening that file

 
 
=?Utf-8?B?Qm9nZGFu?=
Guest
Posts: n/a
 
      9th Mar 2007
Hi there,

The facts:
- I have a folder with 50-60 files, each file having more than 10 sheets;
- the files are pretty big (some of them 40mb+) and are linked to many other
files from various locations from the network;

What I would like to do is:
- to verify whether all files are comprising a sheet named for example "Abc";

The code currently used by me is doing this check, but it is necessary to
open each file from the respective folder. The issue is that due to big
number of files, size and links, the execution of this code takes few hours.
Thus, my code is useless.

The question: is it possible to make this test without opening the files?

Many thanks in advance,

Bogdan
 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      9th Mar 2007
Check out using ADO. Then each workbook is viewed as a database, with
worksheets as tables.

NickHK

"Bogdan" <(E-Mail Removed)> wrote in message
news:E97C3FB1-CA5D-4574-8814-(E-Mail Removed)...
> Hi there,
>
> The facts:
> - I have a folder with 50-60 files, each file having more than 10 sheets;
> - the files are pretty big (some of them 40mb+) and are linked to many

other
> files from various locations from the network;
>
> What I would like to do is:
> - to verify whether all files are comprising a sheet named for example

"Abc";
>
> The code currently used by me is doing this check, but it is necessary to
> open each file from the respective folder. The issue is that due to big
> number of files, size and links, the execution of this code takes few

hours.
> Thus, my code is useless.
>
> The question: is it possible to make this test without opening the files?
>
> Many thanks in advance,
>
> Bogdan



 
Reply With Quote
 
=?Utf-8?B?Qm9nZGFu?=
Guest
Posts: n/a
 
      9th Mar 2007
Thanks, but I do not know exactly how to use ADO. Can you help me with the
code?

Thank you very much in advance,

Bogdan

"NickHK" wrote:

> Check out using ADO. Then each workbook is viewed as a database, with
> worksheets as tables.
>
> NickHK
>
> "Bogdan" <(E-Mail Removed)> wrote in message
> news:E97C3FB1-CA5D-4574-8814-(E-Mail Removed)...
> > Hi there,
> >
> > The facts:
> > - I have a folder with 50-60 files, each file having more than 10 sheets;
> > - the files are pretty big (some of them 40mb+) and are linked to many

> other
> > files from various locations from the network;
> >
> > What I would like to do is:
> > - to verify whether all files are comprising a sheet named for example

> "Abc";
> >
> > The code currently used by me is doing this check, but it is necessary to
> > open each file from the respective folder. The issue is that due to big
> > number of files, size and links, the execution of this code takes few

> hours.
> > Thus, my code is useless.
> >
> > The question: is it possible to make this test without opening the files?
> >
> > Many thanks in advance,
> >
> > Bogdan

>
>
>

 
Reply With Quote
 
Bob Flanagan
Guest
Posts: n/a
 
      9th Mar 2007
You can try writing a formula to a cell that refers to the workbook and
sheet and cell A1 on the sheet. If it evaluates to a value, then the sheet
exists. If it comes back as an error value, then the sheet doesn't exist.
However, you may get prompted to select an alternate sheet.

Bob Flanagan
Macro Systems
144 Dewberry Drive
Hockessin, Delaware, U.S. 19707

Phone: 302-234-9857, cell 302-584-1771
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel

"Bogdan" <(E-Mail Removed)> wrote in message
news:E97C3FB1-CA5D-4574-8814-(E-Mail Removed)...
> Hi there,
>
> The facts:
> - I have a folder with 50-60 files, each file having more than 10 sheets;
> - the files are pretty big (some of them 40mb+) and are linked to many
> other
> files from various locations from the network;
>
> What I would like to do is:
> - to verify whether all files are comprising a sheet named for example
> "Abc";
>
> The code currently used by me is doing this check, but it is necessary to
> open each file from the respective folder. The issue is that due to big
> number of files, size and links, the execution of this code takes few
> hours.
> Thus, my code is useless.
>
> The question: is it possible to make this test without opening the files?
>
> Many thanks in advance,
>
> Bogdan



 
Reply With Quote
 
Jean-Yves
Guest
Posts: n/a
 
      9th Mar 2007
Hi,

First you need to make a reference to "Microsoft ActiveX Data Objects 2.x
Library
Then adapt the below codse to your needs

sub test
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim x As Integer, i As Integer, nrow As Integer

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
'change the file name in here
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=R:\Statistics\STATIST\Current
Books\Statistics for the books.xls;" & _
"Extended Properties=Excel 8.0;"
.Open
End With
' the table/sheet name is follwed by a $ sign [BRUSSELS CS$]=>
[myworksheetBRUSSELS CS$]
'this recorset open command should give an erro when the table/sheet is not
presnet
rs.Open "Select [ABBR], [RADIO CALLSIGN], [TOTAL] from [BRUSSELS CS$] ORDER
BY [TOTAL] DESC, [ABBR] ;", cn, adOpenDynamic, adLockReadOnly
'count the records
x = 0
'Application.StatusBar = "Counting CS"
Do While rs.EOF = False
x = x + 1
rs.MoveNext
Loop
rs.MoveFirst

Do While rs.EOF = False
tbl.Cell(i, 1).Range.Text = rs.Fields("ABBR").Value
tbl.Cell(i, 2).Range.Text = rs.Fields("RADIO CALLSIGN").Value
tbl.Cell(i, 3).Range.Text = rs.Fields("TOTAL").Value
i = i + 1
rs.MoveNext
Loop
rs.Close

HTH
Regbards
J-Y

"Bogdan" <(E-Mail Removed)> wrote in message
news:5F301D81-AEA0-469E-8631-(E-Mail Removed)...
> Thanks, but I do not know exactly how to use ADO. Can you help me with the
> code?
>
> Thank you very much in advance,
>
> Bogdan
>
> "NickHK" wrote:
>
>> Check out using ADO. Then each workbook is viewed as a database, with
>> worksheets as tables.
>>
>> NickHK
>>
>> "Bogdan" <(E-Mail Removed)> wrote in message
>> news:E97C3FB1-CA5D-4574-8814-(E-Mail Removed)...
>> > Hi there,
>> >
>> > The facts:
>> > - I have a folder with 50-60 files, each file having more than 10
>> > sheets;
>> > - the files are pretty big (some of them 40mb+) and are linked to many

>> other
>> > files from various locations from the network;
>> >
>> > What I would like to do is:
>> > - to verify whether all files are comprising a sheet named for example

>> "Abc";
>> >
>> > The code currently used by me is doing this check, but it is necessary
>> > to
>> > open each file from the respective folder. The issue is that due to big
>> > number of files, size and links, the execution of this code takes few

>> hours.
>> > Thus, my code is useless.
>> >
>> > The question: is it possible to make this test without opening the
>> > files?
>> >
>> > Many thanks in advance,
>> >
>> > Bogdan

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?Qm9nZGFu?=
Guest
Posts: n/a
 
      9th Mar 2007
thank you very much. i'll try it and I'll let you know.

regards,

bogdan

"Jean-Yves" wrote:

> Hi,
>
> First you need to make a reference to "Microsoft ActiveX Data Objects 2.x
> Library
> Then adapt the below codse to your needs
>
> sub test
> Dim cn As ADODB.Connection
> Dim rs As ADODB.Recordset
> Dim x As Integer, i As Integer, nrow As Integer
>
> Set cn = New ADODB.Connection
> Set rs = New ADODB.Recordset
> 'change the file name in here
> With cn
> .Provider = "Microsoft.Jet.OLEDB.4.0"
> .ConnectionString = "Data Source=R:\Statistics\STATIST\Current
> Books\Statistics for the books.xls;" & _
> "Extended Properties=Excel 8.0;"
> .Open
> End With
> ' the table/sheet name is follwed by a $ sign [BRUSSELS CS$]=>
> [myworksheetBRUSSELS CS$]
> 'this recorset open command should give an erro when the table/sheet is not
> presnet
> rs.Open "Select [ABBR], [RADIO CALLSIGN], [TOTAL] from [BRUSSELS CS$] ORDER
> BY [TOTAL] DESC, [ABBR] ;", cn, adOpenDynamic, adLockReadOnly
> 'count the records
> x = 0
> 'Application.StatusBar = "Counting CS"
> Do While rs.EOF = False
> x = x + 1
> rs.MoveNext
> Loop
> rs.MoveFirst
>
> Do While rs.EOF = False
> tbl.Cell(i, 1).Range.Text = rs.Fields("ABBR").Value
> tbl.Cell(i, 2).Range.Text = rs.Fields("RADIO CALLSIGN").Value
> tbl.Cell(i, 3).Range.Text = rs.Fields("TOTAL").Value
> i = i + 1
> rs.MoveNext
> Loop
> rs.Close
>
> HTH
> Regbards
> J-Y
>
> "Bogdan" <(E-Mail Removed)> wrote in message
> news:5F301D81-AEA0-469E-8631-(E-Mail Removed)...
> > Thanks, but I do not know exactly how to use ADO. Can you help me with the
> > code?
> >
> > Thank you very much in advance,
> >
> > Bogdan
> >
> > "NickHK" wrote:
> >
> >> Check out using ADO. Then each workbook is viewed as a database, with
> >> worksheets as tables.
> >>
> >> NickHK
> >>
> >> "Bogdan" <(E-Mail Removed)> wrote in message
> >> news:E97C3FB1-CA5D-4574-8814-(E-Mail Removed)...
> >> > Hi there,
> >> >
> >> > The facts:
> >> > - I have a folder with 50-60 files, each file having more than 10
> >> > sheets;
> >> > - the files are pretty big (some of them 40mb+) and are linked to many
> >> other
> >> > files from various locations from the network;
> >> >
> >> > What I would like to do is:
> >> > - to verify whether all files are comprising a sheet named for example
> >> "Abc";
> >> >
> >> > The code currently used by me is doing this check, but it is necessary
> >> > to
> >> > open each file from the respective folder. The issue is that due to big
> >> > number of files, size and links, the execution of this code takes few
> >> hours.
> >> > Thus, my code is useless.
> >> >
> >> > The question: is it possible to make this test without opening the
> >> > files?
> >> >
> >> > Many thanks in advance,
> >> >
> >> > Bogdan
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
check file exists iccsi Microsoft Access Form Coding 3 6th Feb 2009 05:02 PM
Check if file exists WembleyBear Microsoft Excel Programming 3 19th May 2008 04:39 PM
Check if File exists =?Utf-8?B?TWFudWVs?= Microsoft Access External Data 1 11th Sep 2006 04:04 PM
Check if a file exists =?Utf-8?B?am9uZWZlcg==?= Microsoft Access Form Coding 1 12th Apr 2006 09:12 AM
Check If File Exists.. Brett Davis Microsoft Access Form Coding 1 8th Jun 2005 06:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:31 AM.