Bonjour a tous,
Je cherche a utiliser une 1ere macro me permettant de selectionner plusieurs fichiers dans un dossier, puis d'appliquer a cette selection les deux macros "CopyFileData".
Voici mon code actuel.
Option Explicit
Const SearchFolder As String = "C:\Users\JTALBOT\Desktop\MACRO for E-reporting\"
Const FeuilleSource As String = "DB FCST"
Const SheetSource As String = "Main Page"
Const PlageSource As String = "A5:C45"
Const RangeSource As String = "C3"
Const FeuilleDestination As String = "Sheet1"
Sub Broowser()
Dim hotel_code()
Dim FTF As Integer, N As Integer
hotel_code = Application.GetOpenFilename("XSLX Files (*.xlsx),*.xlsx", , "SELECTION FICHIER(S) TEST", , True)
If IsArray(hotel_code) Then 'test selection multiple
FTF = UBound(hotel_code) 'Nb fichiers selectionnes
For N = 1 To FTF
'code traitement selection fichiers
Call CopyFileDataA5C45(hotel_code(N), ThisWorkbook)
Call CopyFileDataC3(hotel_code(N), ThisWorkbook)
Call SetDispScreenEventUpdating(True)
End Sub
Sub CopyFileDataA5C45(fName As String, wk As Workbook)
Dim ereporting As Workbook
Set ereporting = Workbooks.Open(Filename:=SearchFolder & fName, UpdateLinks:=1)
ereporting.Worksheets(FeuilleSource).Range(PlageSource).Copy
strFile = ereporting.Name
Dim FirstCol As Long
With wk.Worksheets(FeuilleDestination)
FirstCol = .Cells(5, Columns.Count).End(xlToLeft).Column
If FirstCol < 5 Then FirstCol = 1
.Cells(5, FirstCol + 3).Value = fName
.Cells(5, FirstCol + 3).PasteSpecial xlPasteColumnWidths
.Cells(5, FirstCol + 3).PasteSpecial xlPasteValues, , False, False
.Cells(5, FirstCol + 3).PasteSpecial xlPasteFormats, , False, False
End With
ereporting.Close SaveChanges:=False
End Sub
Le pop-up montre " type d'argument ByRef incompatible" pour l'argument en gras.
Une idee pour resoudre ce probleme?
Merci d'avance.
Je cherche a utiliser une 1ere macro me permettant de selectionner plusieurs fichiers dans un dossier, puis d'appliquer a cette selection les deux macros "CopyFileData".
Voici mon code actuel.
Option Explicit
Const SearchFolder As String = "C:\Users\JTALBOT\Desktop\MACRO for E-reporting\"
Const FeuilleSource As String = "DB FCST"
Const SheetSource As String = "Main Page"
Const PlageSource As String = "A5:C45"
Const RangeSource As String = "C3"
Const FeuilleDestination As String = "Sheet1"
Sub Broowser()
Dim hotel_code()
Dim FTF As Integer, N As Integer
hotel_code = Application.GetOpenFilename("XSLX Files (*.xlsx),*.xlsx", , "SELECTION FICHIER(S) TEST", , True)
If IsArray(hotel_code) Then 'test selection multiple
FTF = UBound(hotel_code) 'Nb fichiers selectionnes
For N = 1 To FTF
'code traitement selection fichiers
Call CopyFileDataA5C45(hotel_code(N), ThisWorkbook)
Call CopyFileDataC3(hotel_code(N), ThisWorkbook)
Call SetDispScreenEventUpdating(True)
End Sub
Sub CopyFileDataA5C45(fName As String, wk As Workbook)
Dim ereporting As Workbook
Set ereporting = Workbooks.Open(Filename:=SearchFolder & fName, UpdateLinks:=1)
ereporting.Worksheets(FeuilleSource).Range(PlageSource).Copy
strFile = ereporting.Name
Dim FirstCol As Long
With wk.Worksheets(FeuilleDestination)
FirstCol = .Cells(5, Columns.Count).End(xlToLeft).Column
If FirstCol < 5 Then FirstCol = 1
.Cells(5, FirstCol + 3).Value = fName
.Cells(5, FirstCol + 3).PasteSpecial xlPasteColumnWidths
.Cells(5, FirstCol + 3).PasteSpecial xlPasteValues, , False, False
.Cells(5, FirstCol + 3).PasteSpecial xlPasteFormats, , False, False
End With
ereporting.Close SaveChanges:=False
End Sub
Le pop-up montre " type d'argument ByRef incompatible" pour l'argument en gras.
Une idee pour resoudre ce probleme?
Merci d'avance.
Dernière édition: