Jun 30 2021 01:46 AM
Hello,
I have a code for fussing with several sheets in the same folder by but you have to select the files manually:
this is the code I actually have
This is the code i want to keep and I would like to add automatic selection of all files in a folder
Thanks in advance.
Frédéric
Jun 30 2021 03:13 AM
Here you go:
Sub Fusionner()
Dim wbFusion As Workbook
Dim wbCible As Workbook
Dim shCible As Worksheet
Dim stDossier As String
Dim stFichier As String
With Application.FileDialog(4) ' msoFileDialogFolderPicker
.InitialFileName = ThisWorkbook.Path
If .Show Then
stDossier = .SelectedItems(1) & Application.PathSeparator
Else
Beep
Exit Sub
End If
End With
Set wbFusion = ThisWorkbook
stFichier = Dir(stDossier & "*.xls*")
Do While stFichier <> ""
Set wbCible = Workbooks.Open(stDossier & stFichier)
For Each shCible In wbCible.Worksheets
shCible.Copy After:=wbFusion.Worksheets(wbFusion.Worksheets.Count)
Next shCible
wbCible.Close SaveChanges:=False
stFichier = Dir
Loop
End Sub
Jun 30 2021 05:20 AM
Jun 30 2021 05:23 AM
SolutionReplace
With Application.FileDialog(4) ' msoFileDialogFolderPicker
.InitialFileName = ThisWorkbook.Path
If .Show Then
stDossier = .SelectedItems(1) & Application.PathSeparator
Else
Beep
Exit Sub
End If
End With
with a line that specifies the path:
stDossier = "C:\MyFolder\MySubfolder\"
The path must end in a backslash \
Jun 30 2021 05:23 AM
SolutionReplace
With Application.FileDialog(4) ' msoFileDialogFolderPicker
.InitialFileName = ThisWorkbook.Path
If .Show Then
stDossier = .SelectedItems(1) & Application.PathSeparator
Else
Beep
Exit Sub
End If
End With
with a line that specifies the path:
stDossier = "C:\MyFolder\MySubfolder\"
The path must end in a backslash \