27/06/08 18:17
summerjam
Salve a tutti,
Il mio problema è questo.
Vorrei copiare i dati del primo foglio di più file excel in un unico file.
Ad esempio ho 30 file excel nella stessa cartella.
Ho la necessità di copiare i dati del primo foglio di tutti i file nella cartella in un unico file che vado a creare.
E' possibile tutto ciò???
Vi prego aiutatemi
aaa
28/06/08 8:52
Overflow
ma tu vuoi creare un file excel che contenga tutti i "Fogli1" dei 30 file excel?
Alla fine avrai un file excel con 30 Fogli?
oppure il contenuto di tutti i Fogli1 dei 30 file nel solo Foglio1 del nuovo file excel?
Ultima modifica effettuata da Overflow 28/06/08 8:54
aaa
28/06/08 15:21
summerjam
Allora ti spiego meglio il problema.
Ho una cartella con 30 file excel nominati da 1 fino a 30, i quali al loro interno contengono 5 fogli.
A me servirebbe, se possibile, copiare del primo file tutti i fogli mentre degli altri 29 solo il primo.
Quindi alla fine avrò un unico file excel con 5 fogli dove il primo foglio è l'implementazione di tutti i fogli dei 30 file.
Ho anche un codice che fa quasi a caso mio, che se vuoi posso mostrare, il quale mi fa la sola copia di tutti i primi fogli dei 30 file, mentre io vorrei copiare del primo file tutti i fogli e degli altri 29 solo il primo.
aaa
28/06/08 15:27
dedo
ma che centra con vb scusa? -.-
aaa
28/06/08 15:31
summerjam
tutto questo lo devo fare con il visual basic editor di excel.
aaa
29/06/08 8:55
GrG
Premetto che con excel nn ho la minima pratica, a malapena so come funziona...cmq penso sia meglio che fai vedere il codice che usi...
aaa
30/06/08 6:14
summerjam
Private Sub CommandButton5_Click()
On Error GoTo ErrorHandler
Const cWbExt = "*.xls"
Const cWshIndex = 1
Dim strPathSep As String
Dim strPathName As String
Dim strMyName As String
Dim strFilename As String
Dim wbIn As Excel.Workbook
Dim wshIn As Excel.Worksheet
Dim wshOut As Excel.Worksheet
Dim rngOut As Excel.Range
With Application
.ScreenUpdating = False
.DisplayAlerts = False
strPathSep = .PathSeparator
With .ThisWorkbook
strPathName = .Path
strMyName = .Name
With .Worksheets
Set wshOut = .Add(Before:=.Item(1))
End With
End With
End With
If Right$(strPathName, 1) <> strPathSep Then
strPathName = strPathName & strPathSep
End If
strPathName = strPathName
strFilename = Dir(strPathName & cWbExt, vbNormal)
Do While Len(strFilename)
If strFilename <> strMyName Then
'Debug.Print strFilename
Set wbIn = Workbooks.Open(strPathName & strFilename _
, ReadOnly:=True _
, AddToMru:=False)
'Debug.Print , wbIn.FullName
Set wshIn = wbIn.Worksheets.Item(cWshIndex)
'Debug.Print , , wshIn.Name
With wshOut.UsedRange
If .Rows.Count = 1 Then
Set rngOut = .Cells(1, 1)
Else
Set rngOut = .Resize(1 _
, 1).Offset(.Rows.Count)
End If
With wshIn.Cells
.Range(.Item(1, 1) _
, .Find("*" _
, After:=.Cells(1, 1) _
, LookIn:=xlFormulas _
, LookAt:=xlPart _
, SearchOrder:=xlByRows _
, SearchDirection:=xlPrevious _
, MatchCase:=False) _
).Copy rngOut
End With
End With
wbIn.Close SaveChanges:=False
End If
strFilename = Dir
Loop
ExitProcedure:
With Application
.DisplayAlerts = True
.ScreenUpdating = True
End With
Set rngOut = Nothing
Set wshOut = Nothing
Set wshIn = Nothing
Set wbIn = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Description, vbCritical
Resume ExitProcedure
End Sub
Ultima modifica effettuata da summerjam 30/06/08 6:15
aaa