Problème chemin macro

Private Sub Worksheet_Change(ByVal Target As Range)

Dim CHEMIN As String

Dim FICHIERbase As String

Dim FICHIERcom As String

Dim FICHIERdg As String

CHEMIN = "C:\Users\chris\Desktop\TBS SYSTEM\TBS - TEST YUTR - Copie (2)\"

FICHIERbase = "a-mmg\mmg-raport-tbs-base.xlsm"

FICHIERcom = "formulaire\com.xlsm"

FICHIERdg = "rapport\mmg-raport-tbs-dg.xlsm"

Dim etat As Boolean

If Intersect(Target, [AT3,AT4:AW4]) Is Nothing Then Exit Sub

With Application

.ScreenUpdating = False

.DisplayAlerts = False

etat = .AskToUpdateLinks

.AskToUpdateLinks = False

Workbooks.Open(CHEMIN & FICHIERbase).Close True

.AskToUpdateLinks = True

.DisplayAlerts = True

.ScreenUpdating = True

End With

ThisWorkbook.Save

End Sub

Merci Christophe ! Et n'oublie pas les balises </>, c'est plus simple à lire et à copier

Private Sub Worksheet_Change(ByVal Target As Range)

Dim etat As Boolean
Dim CHEMIN As String
Dim FICHIERbase As String
Dim FICHIERcom As String
Dim FICHIERdg As String
Dim MDP as string

CHEMIN = "C:\Users\chris\Desktop\TBS SYSTEM\TBS - TEST YUTR - Copie (2)\"
FICHIERbase = "a-mmg\mmg-raport-tbs-base.xlsm"
FICHIERcom = "formulaire\com.xlsm"
FICHIERdg = "rapport\mmg-raport-tbs-dg.xlsm"
MDP = "P2020" 'exemple bien sur (possibilité de l'appeler depuis Excel : MDP = range("A1").value si mot passe en A1)

If Intersect(Target, [AT3,AT4:AW4]) Is Nothing Then Exit Sub
With Application
.ScreenUpdating = False
.DisplayAlerts = False
etat = .AskToUpdateLinks
.AskToUpdateLinks = False
Workbooks.Open(filename:=CHEMIN & FICHIERbase, password:=MDP).Close True
.AskToUpdateLinks = True
.DisplayAlerts = True
.ScreenUpdating = True
End With
ThisWorkbook.Save

End Sub

Ici, on considère que le mot de passe est commun à tous les fichiers, quoique ce code ne s'intéresse finalement qu'au fichier BASE...

Cdlt,

Private Sub Worksheet_Change(ByVal Target As Range)

Dim CHEMIN As String

Dim FICHIERbase As String

Dim FICHIERcom As String

Dim FICHIERdg As String

CHEMIN = "C:\Users\chris\Desktop\TBS SYSTEM\TBS - TEST YUTR - Copie (2)\"

FICHIERbase = "a-mmg\mmg-raport-tbs-base.xlsm"

FICHIERcom = "formulaire\com.xlsm"

FICHIERdg = "rapport\mmg-raport-tbs-dg.xlsm"

Dim etat As Boolean

If Intersect(Target, [AT3,AT4:AW4]) Is Nothing Then Exit Sub

With Application

.ScreenUpdating = False

.DisplayAlerts = False

etat = .AskToUpdateLinks

.AskToUpdateLinks = False

Workbooks.Open(CHEMIN & FICHIERbase).Close True

.AskToUpdateLinks = True

.DisplayAlerts = True

.ScreenUpdating = True

End With

ThisWorkbook.Save

End Sub

désolé pour le message précédant, petit problème de sycro.

en actualisant le fichier mmg-raport-tbs-dg, il me demande le mot de passe !

Dim motdepasse$ 'à côté des Dim FichierBase ...

motdepasse = "P2020" 'à côté des FichierBase = "...xlsm"

'puis, appeler ainsi :

Workbooks.Open(Filename:=nomfichieràouvrir,Password:=motdepasse)

je ne comprend pas ou mettre lignes ci-dessus dans la macro ci-dessous?

Private Sub Worksheet_Change(ByVal Target As Range)

Dim CHEMIN As String

Dim FICHIERbase As String

Dim FICHIERcom As String

Dim FICHIERdg As String

CHEMIN = "C:\Users\chris\Desktop\TBS SYSTEM\TBS - TEST YUTR - Copie (2)\"

FICHIERbase = "a-mmg\mmg-raport-tbs-base.xlsm"

FICHIERcom = "formulaire\com.xlsm"

FICHIERdg = "rapport\mmg-raport-tbs-dg.xlsm"

Dim etat As Boolean

If Intersect(Target, [AT3,AT4:AW4]) Is Nothing Then Exit Sub

With Application

.ScreenUpdating = False

.DisplayAlerts = False

etat = .AskToUpdateLinks

.AskToUpdateLinks = False

Workbooks.Open(CHEMIN & FICHIERbase).Close True

.AskToUpdateLinks = True

.DisplayAlerts = True

.ScreenUpdating = True

End With

ThisWorkbook.Save

End Sub

Je t'ai répondu déjà, regarde mon dernier commentaire. Pourrais-tu utiliser les balises stp quand tu postes du code ? C'est le logo </> sur le ruban du commentaire.

Je suis désolé, mais je suis un débutant en macro et je ne comprend pas "utiliser les balises stp quand tu postes du code ? C'est le logo </>"

Non, les balises c'est sur le forum quand tu écris un commentaire, tu as un petit ruban, notamment pour mettre en forme le texte, insérer un fichier, mettre un smiley ou encore insérer du code.

C'est bon sinon ? Tu as vu mon précédent commentaire ?

Rechercher des sujets similaires à "probleme chemin macro"