View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Get sheets name without file open

Disable alerts.

FName = "c:\temp\book2.xls"
Application.DisplayAlerts = False
Set obj = GetObject(FName)
Application.DisplayAlerts = True


"Bartosz" wrote:

I do not know how this code lunches aplication/file, but I get massage with
question about update links during line:
Set obj = GetObject(Folder & FName)
is made,
and in Excel window when I go to [window] [unhide] (I translated menu
names from Polish, so I am not sure about those names in English) I see those
files on list with file hided.

Regards,
Bartosz

"Joel" wrote:

I'm not sure if it really opens the workbook. The code launches an invisible
excel application. By not makeing the workbook visible saves time because
the sceen doesn't need to be updated. I could of used the ADO method to
access the workbook but that would of required some SQL which i think would
of been slower than the methods I proposed.

What also may be quicker is to launch an excell application using
CreateObject and then open the workbook using the application. Make the
CreateObject invisible. It takes time with Getobject to create the
application.

"Bartosz" wrote:

Thanks,
but it still open files (with hiden option) so it takes many time to make it
with many files. And on end of loop this file must be closed (I can writhe
this myself).
But becouse it probably only this way to get this data I use it in my macro.
Thanks again,
Bartosz

"Joel" wrote:

I was looking a the wrong workbooks. Make this change

from
For Each Sht In Sheets
to
For Each Sht In obj.Sheets

"Joel" wrote:

See if this runs quicker

Sub test()

Folder = "c:\temp\"
FName = Dir(Folder & "*.xls")
RowCount = 1
Do While FName < ""
Set obj = GetObject(Folder & FName)
For Each Sht In Sheets
Range("A" & RowCount) = FName
Range("B" & RowCount) = Sht.Name
RowCount = RowCount + 1
Next Sht
Set obj = Nothing
FName = Dir()
Loop


End Sub