Roeland035
Gebruiker
- Lid geworden
- 30 mrt 2015
- Berichten
- 291
Beste forumleden,
Ik wil een macro toepassen op alle files in één folder.
Zover ben ik gelukkig al wel gekomen, maar nadat hij deze macro heeft toegepast op al deze files, moet hij nog één file pakken om daarvan de kolomtitels te pakken.
Momenteel heb ik dit (Het rode is de daadwerkelijke code om die file te selecteren), maar het werkt helaas niet.
Ik wil een macro toepassen op alle files in één folder.
Zover ben ik gelukkig al wel gekomen, maar nadat hij deze macro heeft toegepast op al deze files, moet hij nog één file pakken om daarvan de kolomtitels te pakken.
Momenteel heb ik dit (Het rode is de daadwerkelijke code om die file te selecteren), maar het werkt helaas niet.
Code:
Sub Importeer_omloop()
Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog
'Retrieve Target Folder Path From User
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
myPath = .SelectedItems(1) & "\"
End With
'In Case of Cancel
NextCode:
myPath = myPath
If myPath = "" Then GoTo ResetSettings
'Target File Extension (must include wildcard "*")
myExtension = "*.xls"
'Target Path with Ending Extention
myFile = Dir(myPath & myExtension)
'Loop through each Excel file in folder
Do While myFile <> ""
'Set variable equal to opened workbook
Set wb = Workbooks.Open(filename:=myPath & myFile, Local:=True)
wb.Close True
'Get next file name
myFile = Dir
Loop
[COLOR="#FF0000"] If myFile = "" Then
LatestFile = myFile
Workbooks.Open (myPath & myFile)
Range("a1:aj1").Select
Selection.Copy
'Return to target workbook
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Sheets("Input omloopsnelheidlijst").Select
Range("A4").Select
ActiveSheet.Paste
End If[/COLOR]
'Message Box when tasks are completed
MsgBox "Task Complete!"
ResetSettings:
'Reset Macro Optimization Settings
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub