Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Visual Basic 6 - copia file
Forum - Visual Basic 6 - copia file

Avatar
summerjam (Normal User)
Newbie


Messaggi: 20
Iscritto: 15/04/2008

Segnala al moderatore
Postato alle 20:17
Venerdì, 27/06/2008
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

PM Quote
Avatar
Overflow (Normal User)
Expert


Messaggi: 334
Iscritto: 11/01/2008

Segnala al moderatore
Postato alle 10:52
Sabato, 28/06/2008
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 il 28/06/2008 alle 10:54
PM Quote
Avatar
summerjam (Normal User)
Newbie


Messaggi: 20
Iscritto: 15/04/2008

Segnala al moderatore
Postato alle 17:21
Sabato, 28/06/2008
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.

PM Quote
Avatar
dedo (Normal User)
Rookie


Messaggi: 27
Iscritto: 25/06/2008

Segnala al moderatore
Postato alle 17:27
Sabato, 28/06/2008
ma che centra con vb scusa? -.-

PM Quote
Avatar
summerjam (Normal User)
Newbie


Messaggi: 20
Iscritto: 15/04/2008

Segnala al moderatore
Postato alle 17:31
Sabato, 28/06/2008
tutto questo lo devo fare con il visual basic editor di excel.

PM Quote
Avatar
dedo (Normal User)
Rookie


Messaggi: 27
Iscritto: 25/06/2008

Segnala al moderatore
Postato alle 17:32
Sabato, 28/06/2008
Capito , scusa :asd:

PM Quote
Avatar
GrG (Member)
Guru^2


Messaggi: 3430
Iscritto: 21/08/2007

Segnala al moderatore
Postato alle 10:55
Domenica, 29/06/2008
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...

PM Quote
Avatar
summerjam (Normal User)
Newbie


Messaggi: 20
Iscritto: 15/04/2008

Segnala al moderatore
Postato alle 8:14
Lunedì, 30/06/2008
Codice sorgente - presumibilmente VB.NET

  1. Private Sub CommandButton5_Click()
  2.         On Error GoTo ErrorHandler
  3.         Const cWbExt = "*.xls"
  4.         Const cWshIndex = 1
  5.         Dim strPathSep As String
  6.         Dim strPathName As String
  7.         Dim strMyName As String
  8.         Dim strFilename As String
  9.         Dim wbIn As Excel.Workbook
  10.         Dim wshIn As Excel.Worksheet
  11.         Dim wshOut As Excel.Worksheet
  12.         Dim rngOut As Excel.Range
  13.  
  14.         With Application
  15.             .ScreenUpdating = False
  16.             .DisplayAlerts = False
  17.             strPathSep = .PathSeparator
  18.                 With .ThisWorkbook
  19.                 strPathName = .Path
  20.                 strMyName = .Name
  21.                     With .Worksheets
  22.                     Set wshOut = .Add(Before:=.Item(1))
  23.                     End With
  24.             End With
  25.         End With
  26.         If Right$(strPathName, 1) <> strPathSep Then
  27.         strPathName = strPathName & strPathSep
  28.         End If
  29.         strPathName = strPathName
  30.         strFilename = Dir(strPathName & cWbExt, vbNormal)
  31.         Do While Len(strFilename)
  32.             If strFilename <> strMyName Then
  33.                 'Debug.Print strFilename
  34.                 Set wbIn = Workbooks.Open(strPathName & strFilename _
  35.                 , ReadOnly:=True _
  36.                 , AddToMru:=False)
  37.                 'Debug.Print , wbIn.FullName
  38.                 Set wshIn = wbIn.Worksheets.Item(cWshIndex)
  39.                 'Debug.Print , , wshIn.Name
  40.                 With wshOut.UsedRange
  41.                         If .Rows.Count = 1 Then
  42.                                 Set rngOut = .Cells(1, 1)
  43.                                 Else
  44.                                 Set rngOut = .Resize(1 _
  45.                                 , 1).Offset(.Rows.Count)
  46.                         End If
  47.                     With wshIn.Cells
  48.                         .Range(.Item(1, 1) _
  49.                         , .Find("*" _
  50.                         , After:=.Cells(1, 1) _
  51.                         , LookIn:=xlFormulas _
  52.                         , LookAt:=xlPart _
  53.                         , SearchOrder:=xlByRows _
  54.                         , SearchDirection:=xlPrevious _
  55.                         , MatchCase:=False) _
  56.                         ).Copy rngOut
  57.                     End With
  58.                 End With
  59.                 wbIn.Close SaveChanges:=False
  60.             End If
  61.             strFilename = Dir
  62.         Loop
  63.  
  64. ExitProcedure:
  65.         With Application
  66.             .DisplayAlerts = True
  67.             .ScreenUpdating = True
  68.         End With
  69.         Set rngOut = Nothing
  70.         Set wshOut = Nothing
  71.         Set wshIn = Nothing
  72.         Set wbIn = Nothing
  73.     Exit Sub
  74.  
  75. ErrorHandler:
  76.     MsgBox Err.Description, vbCritical
  77.     Resume ExitProcedure
  78. End Sub


Ultima modifica effettuata da summerjam il 30/06/2008 alle 8:15
PM Quote