Ver Mensaje Individual
  #4  
Antiguo 09/07/08, 19:28:25
Ramon Ramon is offline
Principiante
 
Usuario desde: jul 2008
Versión de Excel: Excel 2003
Conectado desde: España
Mensajes: 2
Predeterminado

Gracias, pero abrir casi 7.000 archivos uno tras otro es lo que intento evitar.

He encontrado un codigo que me va PERO tengo problema con la parte referente a la hoja
Cita:
Sub Summary_cells_from_Different_Workbooks_1()
Dim FileNameXls As Variant
Dim SummWks As Worksheet
Dim ColNum As Integer
Dim myCell As Range, Rng As Range
Dim RwNum As Long, FNum As Long, FinalSlash As Long
Dim ShName As String, PathStr As String
Dim SheetCheck As String, JustFileName As String
Dim JustFolder As String

ShName = "estomejode" '<---- Change"
Set Rng = Range("d3,d5,d8,d9,d10") '<---- Change

'Select the files with GetOpenFilename
FileNameXls = Application.GetOpenFilename(filefilter:="Excel Files, *.xl*", _
MultiSelect:=True)

If IsArray(FileNameXls) = False Then
'do nothing
Else

With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

'Add a new workbook with one sheet for the Summary
Set SummWks = Workbooks.Add(1).Worksheets(1)

'The links to the first workbook will start in row 2
RwNum = 1

For FNum = LBound(FileNameXls) To UBound(FileNameXls)
ColNum = 1
RwNum = RwNum + 1
FinalSlash = InStrRev(FileNameXls(FNum), "\")
JustFileName = Mid(FileNameXls(FNum), FinalSlash + 1)
JustFolder = Left(FileNameXls(FNum), FinalSlash - 1)

'copy the workbook name in column A
SummWks.Cells(RwNum, 1).Value = JustFileName

'build the formula string
JustFileName = WorksheetFunction.Substitute(JustFileName, "'", "''")
PathStr = "'" & JustFolder & "\[" & JustFileName & "]" & ShName & "'!"

On Error Resume Next
SheetCheck = ExecuteExcel4Macro(PathStr & Range("A1").Address(, , xlR1C1))
If Err.Number <> 0 Then
'If the sheet not exist in the workbook the row color will be Yellow.
SummWks.Cells(RwNum, 1).Resize(1, Rng.Cells.Count + 1) _
.Interior.Color = vbYellow
Else
For Each myCell In Rng.Cells
ColNum = ColNum + 1
SummWks.Cells(RwNum, ColNum).Formula = _
"=" & PathStr & myCell.Address
Next myCell
End If
On Error GoTo 0
Next FNum

' Use AutoFit to set the column width in the new workbook
SummWks.UsedRange.Columns.AutoFit

MsgBox "The Summary is ready, save the file if you want to keep it"

With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End If
End Sub
Cada libro me ha puesto el nombre del archivo en el nombre de la hoja..
La solucion es encontrar como hacer que donde pongo "estomejode" ponga el nombre de la hoja corelativamente. Ya que mis archivos se llaman todos igual seguido de un numero (para facilitar las cosas, claro)

Algun@ tiene una idea ? que no me deja con el asterisco, no me sirve de nada poner "estomejode*"

La unica solucion que le veo es poner el mismo nombre a la 1º hoja, Hoja1, como viene por defecto cuando abres un libro nuevo. Pero ahi tengo otro problema el tener que hacerlo UNO A UNO. Es que es una gran cantidad de libros. Alguna idea??

Gracias

Última edición por Ramon fecha: 10/07/08 a las 09:30:08.
Responder Con Cita