Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Nom du classeur contenant la macro en variable dans cette dernière

3 réponses
Avatar
snoopix
Bonjour, et bonne année !

Je bute sur un problème qui me paraît insoluble, d'où mon inscription et ma demande d'aide !
Dans un classeur ouvert, un bouton active une macro, qui doit ouvrir un autre classeur ("Honoraires 2009") et récupérer dans le premier (celui de la macro "INDIVISION 1") des valeurs sur la feuille ("Fiche locataire") pour les insérer dans ("Honoraires 2009").

La macro fonctionne, la voici :

Private Sub CommandButton6_Click()
'
' HonorairesMiseLocation Macro
'

Workbooks.Open Filename:="E:\EDIRFA 2009\HONORAIRES 2009\A"
Sheets("Facturation").Select
Sheets("Facturation").Range("C16").Select

ActiveCell.FormulaR1C1 = "='[ThisWorkbook]FICHE LOCATAIRE'!R42C8"
Sheets("Facturation").Range("C18:G18").Select
ActiveCell.FormulaR1C1 = "='[ThisWorkbook]FICHE LOCATAIRE'!R13C3:R13C6"
Sheets("Facturation").Range("C20:G20").Select
ActiveCell.FormulaR1C1 = "='[ThisWorkbook]FICHE LOCATAIRE'!R21C3:R21C6"
Sheets("Facturation").Range("C22:G22").Select
ActiveCell.FormulaR1C1 = "='[ThisWorkbook]FICHE LOCATAIRE'!R29C3:R29C6"
Sheets("Facturation").Range("D25:F25").Select
ActiveCell.FormulaR1C1 = "='[ThisWorkbook]FICHE LOCATAIRE'!R42C4"
Sheets("Facturation").Range("D26").Select
Sheets("HONORAIRES DE MISE EN LOCATION").Select
Sheets("HONORAIRES DE MISE EN LOCATION").Range("L12").Select

End Sub

Je voudrais pouvoir remplacer le nom du classeur contenant la macro, à savoir "INDIVISION 1" par une variable qui prendrait elle même le nom de ce classeur, sans le nommer.
Ceci dans le but de pouvoir dupliquer un grand nombre de foi le classeur contenant la macro, sans devoir corriger à chaque foi le code de chaque classeur.

C'est long, mais j'ai essayer d'être clair.

Si vous avez déjà eu le cas ... merci de votre aide.
Je n'ai pas trouver d'exemple utilisable pour ce cas ...

3 réponses

Avatar
snoopix
snoopix a écrit le 19/01/2010 à 23h33 :
Bonjour, et bonne année !

Je bute sur un problème qui me paraît insoluble, d'où mon
inscription et ma demande d'aide !
Dans un classeur ouvert, un bouton active une macro, qui doit ouvrir un autre
classeur ("Honoraires 2009") et récupérer dans le
premier (celui de la macro "INDIVISION 1") des valeurs sur la feuille
("Fiche locataire") pour les insérer dans ("Honoraires
2009").

La macro fonctionne, la voici :

Private Sub CommandButton6_Click()
'
' HonorairesMiseLocation Macro
'

Workbooks.Open Filename:="E:EDIRFA 2009HONORAIRES 2009A"
Sheets("Facturation").Select
Sheets("Facturation").Range("C16").Select

ActiveCell.FormulaR1C1 = "='[ThisWorkbook]FICHE
LOCATAIRE'!R42C8"
Sheets("Facturation").Range("C18:G18").Select
ActiveCell.FormulaR1C1 = "='[ThisWorkbook]FICHE
LOCATAIRE'!R13C3:R13C6"
Sheets("Facturation").Range("C20:G20").Select
ActiveCell.FormulaR1C1 = "='[ThisWorkbook]FICHE
LOCATAIRE'!R21C3:R21C6"
Sheets("Facturation").Range("C22:G22").Select
ActiveCell.FormulaR1C1 = "='[ThisWorkbook]FICHE
LOCATAIRE'!R29C3:R29C6"
Sheets("Facturation").Range("D25:F25").Select
ActiveCell.FormulaR1C1 = "='[ThisWorkbook]FICHE
LOCATAIRE'!R42C4"
Sheets("Facturation").Range("D26").Select
Sheets("HONORAIRES DE MISE EN LOCATION").Select
Sheets("HONORAIRES DE MISE EN
LOCATION").Range("L12").Select

End Sub

Je voudrais pouvoir remplacer le nom du classeur contenant la macro, à
savoir "INDIVISION 1" par une variable qui prendrait elle même
le nom de ce classeur, sans le nommer.
Ceci dans le but de pouvoir dupliquer un grand nombre de foi le classeur
contenant la macro, sans devoir corriger à chaque foi le code de chaque
classeur.

C'est long, mais j'ai essayer d'être clair.

Si vous avez déjà eu le cas ... merci de votre aide.
Je n'ai pas trouver d'exemple utilisable pour ce cas ...


La macro contient une erreur, à la place de ThisWorKbook, c'est INDIVISION 1 ...
J'avais essayé ...
Avatar
FdeCourt
Salut,

Essayes avec cette macros

Private Sub CommandButton6_Click()
'
' HonorairesMiseLocation Macro
'
Dim honoraires As Workbook
Dim facturation As Worksheet
Dim monFichier As String

monFichier = ThisWorkbook.Path & "[" & ThisWorkbook.Name & "]"
Set honoraires = Workbooks.Open(Filename:="E:EDIRFA
2009HONORAIRES 2009A")
Set facturation = honoraires.Sheets("Facturation")

With facturation
.Range("C16").FormulaR1C1 = "='" & monFichier & "FICHE
LOCATAIRE'!R42C8"
.Range("C18:G18").FormulaR1C1 = "='" & monFichier & "FICHE
LOCATAIRE'!R13C3:R13C6"
.Range("C20:G20").FormulaR1C1 = "='" & monFichier & "FICHE
LOCATAIRE'!R21C3:R21C6"
.Range("C22:G22").FormulaR1C1 = "='" & monFichier & "FICHE
LOCATAIRE'!R29C3:R29C6"
.Range("D25:F25").FormulaR1C1 = "='" & monFichier & "FICHE
LOCATAIRE'!R42C4"
End With
honoraires.Sheets("HONORAIRES DE MISE EN LOCATION").Select
honoraires.Sheets("HONORAIRES DE MISE EN LOCATION").Range
("L12").Select
Set honoraires = Nothing: Set facturation = Nothing
End Sub

Ceci dit, je ne comprend pas trop l'intérêt des formules !!!!

Cordialement,

F.
Avatar
snoopix
FdeCourt a écrit le 20/01/2010 à 13h12 :
Salut,

Essayes avec cette macros

Private Sub CommandButton6_Click()
'
' HonorairesMiseLocation Macro
'
Dim honoraires As Workbook
Dim facturation As Worksheet
Dim monFichier As String

monFichier = ThisWorkbook.Path & "[" & ThisWorkbook.Name
& "]"
Set honoraires = Workbooks.Open(Filename:="E:EDIRFA
2009HONORAIRES 2009A")
Set facturation = honoraires.Sheets("Facturation")

With facturation
.Range("C16").FormulaR1C1 = "='" & monFichier &
"FICHE
LOCATAIRE'!R42C8"
.Range("C18:G18").FormulaR1C1 = "='" & monFichier &
"FICHE
LOCATAIRE'!R13C3:R13C6"
.Range("C20:G20").FormulaR1C1 = "='" & monFichier &
"FICHE
LOCATAIRE'!R21C3:R21C6"
.Range("C22:G22").FormulaR1C1 = "='" & monFichier &
"FICHE
LOCATAIRE'!R29C3:R29C6"
.Range("D25:F25").FormulaR1C1 = "='" & monFichier &
"FICHE
LOCATAIRE'!R42C4"
End With
honoraires.Sheets("HONORAIRES DE MISE EN LOCATION").Select
honoraires.Sheets("HONORAIRES DE MISE EN LOCATION").Range
("L12").Select
Set honoraires = Nothing: Set facturation = Nothing
End Sub

Ceci dit, je ne comprend pas trop l'intérêt des formules !!!!

Cordialement,

F.


MERCI BEAUCOUP ÇA FONCTIONNE NICKEL !!