Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default list excel wookbooks and worksheets

Hi,
Is there a way to utilize a bit of VBA code that will create a list of excel workbooks in a directory with all the corresponding worksheets in an adjacent column with the contents of a specific cell, say C1, next to that?

Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default list excel wookbooks and worksheets

Hi,

Am Wed, 7 Oct 2015 08:15:15 -0700 (PDT) schrieb :

Is there a way to utilize a bit of VBA code that will create a list of excel workbooks in a directory with all the corresponding worksheets in an adjacent column with the contents of a specific cell, say C1, next to that?


try:

Sub Test()
Dim objFSO As Object, objFolder As Object, objFile As Object
Dim varHeader As Variant, varOut() As Variant
Dim i As Long, n As Long

Application.ScreenUpdating = False
Application.DisplayAlerts = False

'Modify your path
Const myPath = "E:\Excel_NG\AktuelleProjekte\"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(myPath)

varHeader = Array("Workbook", "Sheets", "C1")
With ActiveSheet
.Range("A1:C1") = varHeader
.Range("A1:C1").Font.Bold = True
For Each objFile In objFolder.Files
If InStr(objFile.Name, ".xls") Then
.Cells(Rows.Count, 2).End(xlUp)(2).Offset(, -1) =
objFile.Name
Workbooks.Open myPath & objFile.Name
n = 0
ReDim Preserve varOut(1, Worksheets.Count - 1)
For i = 1 To ActiveWorkbook.Worksheets.Count
varOut(0, n) = Worksheets(i).Name
varOut(1, n) = Worksheets(i).Range("C1").Value
n = n + 1
Next
ActiveWorkbook.Close savechanges:=False
.Cells(Rows.Count, 2).End(xlUp)(2).Resize(n, 2) _
= Application.Transpose(varOut)
End If
Next
.Columns("A:C").AutoFit
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default list excel wookbooks and worksheets

On Wednesday, October 7, 2015 at 11:15:33 AM UTC-4, wrote:
Hi,
Is there a way to utilize a bit of VBA code that will create a list of excel workbooks in a directory with all the corresponding worksheets in an adjacent column with the contents of a specific cell, say C1, next to that?

Thanks in advance.


I'm getting a runtime error '1004', it can't find the file
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default list excel wookbooks and worksheets

Hi,

Am Wed, 7 Oct 2015 10:13:18 -0700 (PDT) schrieb :

I'm getting a runtime error '1004', it can't find the file


have you modified the path correctly?
At the end of the path must be a backslash.


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default list excel wookbooks and worksheets

On Wednesday, October 7, 2015 at 11:15:33 AM UTC-4, wrote:
Hi,
Is there a way to utilize a bit of VBA code that will create a list of excel workbooks in a directory with all the corresponding worksheets in an adjacent column with the contents of a specific cell, say C1, next to that?

Thanks in advance.


that was it! works perfectly now, thank you so much for your help.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default list excel wookbooks and worksheets

Claus,
Do you know you can do the same using ADO without having to open the
Excel files? The file serves in ADO as the database, and its sheets
serve as the database tables. Thus, filename is returned via Dir() and
SQL for the list of table names.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default list excel wookbooks and worksheets

Hi Garry,

Am Wed, 07 Oct 2015 14:21:42 -0400 schrieb GS:

Do you know you can do the same using ADO without having to open the
Excel files? The file serves in ADO as the database, and its sheets
serve as the database tables. Thus, filename is returned via Dir() and
SQL for the list of table names.


and how do I get a cell value?


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default list excel wookbooks and worksheets

Hi Garry,

Am Wed, 07 Oct 2015 14:21:42 -0400 schrieb GS:

Do you know you can do the same using ADO without having to open the
Excel files? The file serves in ADO as the database, and its sheets
serve as the database tables. Thus, filename is returned via Dir()
and SQL for the list of table names.


and how do I get a cell value?


Regards
Claus B.


You query the range. Here's an example tutorial by Rob Bovey, one of
the authors of *Pro Excel Development*...

http://www.appspro.com/conference/Da...rogramming.zip

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default list excel wookbooks and worksheets

Hi Garry,

Am Wed, 07 Oct 2015 14:40:59 -0400 schrieb GS:

http://www.appspro.com/conference/Da...rogramming.zip


thank you. I will look for the code tomorrow.


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default list excel wookbooks and worksheets

Hi Garry,

Am Wed, 07 Oct 2015 14:21:42 -0400 schrieb GS:

Do you know you can do the same using ADO without having to open the
Excel files? The file serves in ADO as the database, and its sheets
serve as the database tables. Thus, filename is returned via Dir()
and SQL for the list of table names.


and how do I get a cell value?


Regards
Claus B.


If the cell has a defined name it doesn't need to be at a specific
address. For example, if the workbooks contain quotes/estimates of
various numbers of items, the SubTotal, Tax, and Total can be anywhere
on the sheet. You can use the defined name in the ADO query as the
range ref when the address will be unknown...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


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
Comparing Wookbooks Chris Hankin[_4_] Excel Programming 6 November 11th 08 10:17 PM
Problem w/Sharing Wookbooks Bec Excel Discussion (Misc queries) 2 May 2nd 08 11:24 PM
How do I make normal view my default in excel 2007 wookbooks? gkendron Setting up and Configuration of Excel 0 January 1st 08 04:54 PM
adding wookbooks together Gary Excel Discussion (Misc queries) 2 May 29th 05 11:53 PM
Compare and Merge Wookbooks Dan Powell Excel Worksheet Functions 3 March 9th 05 11:50 PM


All times are GMT +1. The time now is 07:18 AM.

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"