Problème Macro execution en spécifiant un chemin

Bonjour,

Voila j'ai une macro qui fonctionne le seul problème c'est je suis obliger de la mettre dans un répertoire.

en fait je voudrais pouvoir l'exécuter en spécifiant le chemin et le répertoire sur laquelle elle effectue le traitement, pour info je suis novice.

Si quelqu'un peut m'aider je lui en serai très reconnaissant car cela fais un temps fou que j'y passe sans trouvé de solution.

Merci d'avance pour votre aide.

Si dessous le code en question :

Public Sub Consolidation_donnees()

Dim Wb As Workbook

Dim Table As ListObject

Dim strPath As String, strFilename As String

Dim rCell As Range

Dim lastRow As Long

Const LROW As Byte = 21

Application.ScreenUpdating = False

Set Table = ActiveSheet.ListObjects(1)

With Table

If Not .DataBodyRange Is Nothing Then .DataBodyRange.Delete

Set rCell = .InsertRowRange.Cells(1)

End With

strPath = ThisWorkbook.Path & Application.PathSeparator

strFilename = Dir(strPath & "*.xls*")

While strFilename <> ""

If strFilename <> ThisWorkbook.Name Then

Set Wb = Workbooks.Open(strPath & strFilename)

With Wb.Worksheets("SuiviPlanning")

lastRow = .Cells(.Rows.Count, 1).End(xlUp).Row - 1

.Cells(LROW, 1).Resize(lastRow - LROW + 1, 8).Copy

rCell.PasteSpecial xlPasteValues

Application.CutCopyMode = 0

Set rCell = Table.HeaderRowRange.Cells(1).Offset(Table.ListRows.Count + 1)

End With

Application.EnableEvents = False

Wb.Close savechanges:=False

Set Wb = Nothing

End If

strFilename = Dir

Wend

Set rCell = Nothing: Set Table = Nothing

Cordialement,

Spindral

Bonjour,

sur cette ligne

strPath = ThisWorkbook.Path & Application.PathSeparator

remplacer ThisWorkbook.Path par votre chemin de répertoire

par exemple si je voudrais mon répertoire "Documents, j'écrirais,

strPath = "C:\Users\isabelle\Documents" & Application.PathSeparator

Bonjour,

Merci cela fonctionne correctement,

Cordialement,

Spindral

Rechercher des sujets similaires à "probleme macro execution specifiant chemin"