Moderatori: Anthony47, Flash30005
Option Explicit
Sub Leggi_Dati_e_Copia_Celle()
Dim Percorso As String, Estensione As String, MioFile As String, I As Integer, RR As Integer, Messaggio As String
Dim mFile As Excel.Application, mWBook_In As Excel.Workbook, mWBook_Out As Excel.Workbook, mWs_In As Excel.Worksheet, mWs_Out As Excel.Worksheet, vValue As Variant
Application.ScreenUpdating = False
Percorso = "D:\Temp\Excel\" ' <<---- SCRIVI IL NOME DEL TUO PERCORSO
Set mFile = New Excel.Application
Set mWBook_Out = ActiveWorkbook
Set mWs_Out = mWBook_Out.Worksheets(1) ' <<---- "1" rappresenta il primo foglio del file sul quale scrivere i dati dei vari fogli
RR = mWs_Out.Range("A" & Rows.Count).End(xlUp).Row
If RR = 1 Then
RR = 2
End If
mWs_Out.Range("A2:E" & RR).ClearContents ' <<---- cancella i dati presenti nel file sul quale scrivere i dati dei vari fogli
Estensione = "XLS"
MioFile = Dir(Percorso & "*." & Estensione)
On Error GoTo Continua
Set mWBook_In = mFile.Workbooks.Open(Percorso & MioFile)
Set mWs_In = mWBook_In.Worksheets(1) ' <<---- "1" rappresenta il primo foglio del file che viene elaborato
I = 1
Do While MioFile <> ""
I = I + 1
mWs_Out.Cells(I, 1) = mWs_In.Range("B17")
mWs_Out.Cells(I, 2) = mWs_In.Range("B18")
mWs_Out.Cells(I, 3) = mWs_In.Range("B3")
mWs_Out.Cells(I, 4) = mWs_In.Range("B5")
mWs_Out.Cells(I, 5) = mWs_In.Range("B2")
mWBook_In.Close SaveChanges:=False
MioFile = Dir()
Set mWBook_In = mFile.Workbooks.Open(Percorso & MioFile)
Set mWs_In = mWBook_In.Worksheets(1) ' <<---- "1" rappresenta il primo foglio del file che viene elaborato
Loop
Continua:
Application.ScreenUpdating = True
If I = 0 Then
Messaggio = "Nel percorso: ''" & Percorso & "''" & vbCrLf & vbCrLf & "Non sono stati trovati file aventi estensione ''" & Estensione & "''"
Else
Messaggio = "Effettuata elaborazione di: ''" & I & "'' File"
End If
MsgBox Messaggio
Set mWBook_In = Nothing
Set mWBook_Out = Nothing
Set mWs_In = Nothing
Set mWs_Out = Nothing
Set mFile = Nothing
End Sub
Torna a Applicazioni Office Windows
Mettere tutto MAIUSCOLO un range di celle Autore: raimea |
Forum: Applicazioni Office Windows Risposte: 7 |
Trasformare celle con formattazioni in html Autore: servicedynergy |
Forum: Applicazioni Office Windows Risposte: 5 |
Visitano il forum: Nessuno e 17 ospiti