Een familie van Microsoft-spreadsheetsoftware met hulpmiddelen voor het analyseren, in kaart brengen en communiceren van gegevens.
Hoi Jan,
Je zou met deze macro e.e.a. kunnen doen als je:
- De zes Excel bestanden al klaar hebt staan (liefst in 1 map)
- De te importeren bestanden niet in een andere map komen dan waar ze stonden.
- plaats de macro in een ander bestand dan 1 van de zes en voer de sub "Start"
uit.
Sub Start()
Dim vExcelFiles As Variant
Dim sFileName As Variant
vExcelFiles = Application.GetOpenFilename("Microsoft Excel files *.xls*, _
*.xls*)", , "Kies de bij te werken Excel bestanden", , True)
If IsEmpty(vExcelFiles) Then Exit Sub
If IsArray(vExcelFiles) Then
For Each sFileName In vExcelFiles
UpdateWb CStr(sFileName)
Next
Else
End If
End Sub
Sub UpdateWb(sFileName As String)
Dim oQt As QueryTable
Dim oSh As Worksheet
Dim sPart As String
Dim sPath As String
Dim sFile As String
Dim sNewFile As String
Workbooks.Open sFileName
For Each oSh In Worksheets
For Each oQt In oSh.QueryTables
If oQt.Connection Like "TEXT;*" Then
'Connection ziet er zo uit:
'TEXT;C:\Users\Administrator\Documents\SiteVisits.txt
sPart = oQt.Connection
'Bestandsnaam en pad
sPart = Split(sPart, ";")(1)
sFile = Mid(sPart, InStrRev(sPart, "") + 1, Len(sPart))
sPath = Replace(sPart, sFile, "")
'Hier ga ik ervan uit, dat het nieuwe bestandin dezelfde
'map staat als het vorige
'en dat de eerste 5 karakters van de bestandsnaam
'hetzelfde blijven
sNewFile = Dir(sPath & Left(sFile, 5) & "*.txt")
If Len(sNewFile) > 0 Then
If sNewFile <> sFile Then
oQt.Connection = Replace(oQt.Connection, _
sPath & sFile, sPath & sNewFile)
End If
End If
'Import vernieuwen
oQt.Refresh False
End If
Next
Next
If ActiveWorkbook.Name <> ThisWorkbook.Name Then
ActiveWorkbook.Close True
End If
End Sub