nbuytaer
Messages postés3Date d'inscriptionmercredi 8 octobre 2008StatutMembreDernière intervention 2 novembre 2009
-
1 nov. 2009 à 21:08
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 2021
-
3 nov. 2009 à 07:07
Bonjour, j'ai reçu un document avec des macros pour le boulot, il y a juste un petit hic le chemin d'accès entre les deux fichiers est défini dans la macro, je voudrai le remplacer par un chemin relatif de manière à pouvoir l'utiliser sur mon disque dur et depuis n'importe quel poste
voici le code de la macro
Sub Enregistrer1()
On Error GoTo ErreurOuverture
Dim NomFich As String, Chemin As String
Dim xlApp As Object
Dim xlCL1 As Object
Dim CelPercevoir As Range
Chemin = "C:\classeur" (voilà ce qui me gêne)
NomFich = "edmu-general.xlsm" 'sans le chemin
Set xlApp = CreateObject("Excel.Application") 'Si Excel est fermé, génère une erreur
Set xlApp = GetObject(, "Excel.Application")
On Error Resume Next
'si le fichier est fermé, génère une erreur
Set xlCL1 = xlApp.Workbooks(NomFich)
'MsgBox Err.Description, , Err.Source
Set xlCL1 = xlApp.Workbooks.Open(FileName:=Chemin & NomFich, ReadOnly:=False)
Set rngNiveau = ActiveDocument.Bookmarks("niveau").Range
Set rngNumero = ActiveDocument.Bookmarks("numero").Range
If rngNiveau = "Sixième" Then
ligne = 0
End If
If rngNiveau = "Cinquième" Then
ligne = 1
End If
If rngNiveau = "Quatrième" Then
ligne = 2
End If
If rngNiveau = "Troisième" Then
ligne = 3
End If
If rngNumero = "01" Then
colonne = 0
End If
If rngNumero = "02" Then
colonne = 1
End If
If rngNumero = "03" Then
colonne = 2
End If
If rngNumero = "04" Then
colonne = 3
End If
If rngNumero = "05" Then
colonne = 4
End If
ActiveDocument.Range(ActiveDocument.Bookmarks("percevoir00"). _
Range.Start, ActiveDocument.Bookmarks("percevoir02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(3 + ligne * 57, 3 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("culture00"). _
Range.Start, ActiveDocument.Bookmarks("culture02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(5 + ligne * 57, 3 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("question00"). _
Range.Start, ActiveDocument.Bookmarks("question02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(7 + ligne * 57, 2 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("voix00"). _
Range.Start, ActiveDocument.Bookmarks("voix02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(10 + ligne * 57, 3 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("styles00"). _
Range.Start, ActiveDocument.Bookmarks("styles02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(13 + ligne * 57, 3 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("timbre00"). _
Range.Start, ActiveDocument.Bookmarks("timbre02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(15 + ligne * 57, 3 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("dynamique00"). _
Range.Start, ActiveDocument.Bookmarks("dynamique02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(17 + ligne * 57, 3 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("rythme00"). _
Range.Start, ActiveDocument.Bookmarks("rythme02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(19 + ligne * 57, 3 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("successif00"). _
Range.Start, ActiveDocument.Bookmarks("successif02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(21 + ligne * 57, 3 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("forme00"). _
Range.Start, ActiveDocument.Bookmarks("forme02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(23 + ligne * 57, 3 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("oeuvre00"). _
Range.Start, ActiveDocument.Bookmarks("oeuvre02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(25 + ligne * 57, 2 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("timbre00b"). _
Range.Start, ActiveDocument.Bookmarks("timbre02b").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(29 + ligne * 57, 3 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("dynamique00b"). _
Range.Start, ActiveDocument.Bookmarks("dynamique02b").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(31 + ligne * 57, 3 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("rythme00b"). _
Range.Start, ActiveDocument.Bookmarks("rythme02b").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(33 + ligne * 57, 3 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("successif00b"). _
Range.Start, ActiveDocument.Bookmarks("successif02b").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(35 + ligne * 57, 3 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("forme00b"). _
Range.Start, ActiveDocument.Bookmarks("forme02b").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(37 + ligne * 57, 3 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("vocabulaire00"). _
Range.Start, ActiveDocument.Bookmarks("vocabulaire02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(39 + ligne * 57, 2 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("oeuvrecomp00"). _
Range.Start, ActiveDocument.Bookmarks("oeuvrecomp02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(41 + ligne * 57, 2 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("socle00"). _
Range.Start, ActiveDocument.Bookmarks("socle02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(43 + ligne * 57, 2 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("histoire00"). _
Range.Start, ActiveDocument.Bookmarks("histoire02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(45 + ligne * 57, 2 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("theme00"). _
Range.Start, ActiveDocument.Bookmarks("theme02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(47 + ligne * 57, 2 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("origine00"). _
Range.Start, ActiveDocument.Bookmarks("origine02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(49 + ligne * 57, 2 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("description00"). _
Range.Start, ActiveDocument.Bookmarks("description02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(51 + ligne * 57, 2 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("materiel00"). _
Range.Start, ActiveDocument.Bookmarks("materiel02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(53 + ligne * 57, 2 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("auteur00"). _
Range.Start, ActiveDocument.Bookmarks("auteur02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(57 + ligne * 57, 2 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("voixeval00"). _
Range.Start, ActiveDocument.Bookmarks("voixeval02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(9 + ligne * 57, 4 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("styleseval00"). _
Range.Start, ActiveDocument.Bookmarks("styleseval02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(12 + ligne * 57, 4 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("timbreeval00"). _
Range.Start, ActiveDocument.Bookmarks("timbreeval02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(15 + ligne * 57, 4 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("dynamiqueeval00"). _
Range.Start, ActiveDocument.Bookmarks("dynamiqueeval02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(17 + ligne * 57, 4 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("rythmeeval00"). _
Range.Start, ActiveDocument.Bookmarks("rythmeeval02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(19 + ligne * 57, 4 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("successifeval00"). _
Range.Start, ActiveDocument.Bookmarks("successifeval02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(21 + ligne * 57, 4 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("formeeval00"). _
Range.Start, ActiveDocument.Bookmarks("formeeval02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(23 + ligne * 57, 4 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("projet00"). _
Range.Start, ActiveDocument.Bookmarks("projet02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(25 + ligne * 57, 4 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("repertoire00"). _
Range.Start, ActiveDocument.Bookmarks("repertoire02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(27 + ligne * 57, 4 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("timbreeval00b"). _
Range.Start, ActiveDocument.Bookmarks("timbreeval02b").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(29 + ligne * 57, 4 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("dynamiqueeval00b"). _
Range.Start, ActiveDocument.Bookmarks("dynamiqueeval02b").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(31 + ligne * 57, 4 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("rythmeeval00b"). _
Range.Start, ActiveDocument.Bookmarks("rythmeeval02b").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(33 + ligne * 57, 4 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("successifeval00b"). _
Range.Start, ActiveDocument.Bookmarks("successifeval02b").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(35 + ligne * 57, 4 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("formeeval00b"). _
Range.Start, ActiveDocument.Bookmarks("formeeval02b").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(37 + ligne * 57, 4 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
ActiveDocument.Range(ActiveDocument.Bookmarks("b2i00"). _
Range.Start, ActiveDocument.Bookmarks("b2i02").Range.End).Select
Selection.Copy
With New DataObject
.GetFromClipboard
resultat = .GetText(1)
End With
xlCL1.Worksheets("Feuil1").Cells(43 + ligne * 57, 4 + colonne * 3).Select
ActiveCell.FormulaR1C1 = resultat
On Error GoTo ErreurOuverture
xlCL1.SaveAs "c:\classeur\edmu-general.xlsm"
xlCL1.Close True
xlApp.Quit
Exit Sub
ErreurOuverture:
MsgBox Err.Number
MsgBox Err.Description, , Err.Source
If Err.Number = 91 Then
MsgBox "Le classeur n'existe pas ou a été déplacé ; veuillez réinstaller l'application."
ElseIf Err.Number = 1004 Then
MsgBox "Le classeur est déjà ouvert ; veuillez fermer l'application."
Exit Sub
End If
End Sub
Merci pour votre aide
Je suis loin d'être un pro et j'ai donc bien trouvé des éléments de réponse mais je ne sais pas trop comment les utilisés
nbuytaer
Messages postés3Date d'inscriptionmercredi 8 octobre 2008StatutMembreDernière intervention 2 novembre 2009 1 nov. 2009 à 21:56
il me semble que cet option là doit être réalisable
"Cet exemple montre comment remplacer le dossier actif par le chemin d'accès du modèle attaché au document actif.
Visual Basic pour Applications
ChDir ActiveDocument.AttachedTemplate.Path"
je suppose qu'il faut définir Attachedtemplate
donc je jette un coup d'oeil dans l'aide et me revoilà avec le même problème
Cet exemple montre comment attacher le modèle « Letter.dot » au document actif.
Visual Basic pour Applications
ActiveDocument.AttachedTemplate = "C:\Templates\Letter.dot"
Je suis désolé mais j'ai de grosse lacune en programmation, donc là je patauge un peu.
cs_Jack
Messages postés14006Date d'inscriptionsamedi 29 décembre 2001StatutModérateurDernière intervention28 août 201579 2 nov. 2009 à 00:54
Salut
Et tu postes 40000 lignes de code pour une simple histoire de variable ?
Evites à l'avenir, d'une part parce que cela ne sert à rien, d'autre part parece que les membres, voyant ce code sans fin partent au galop !
jmf0 t'a donné la solution : La variable système dont il t'a parlé renvoie le chemin.
A toi de remplacer ton chemin 'en dir' par celui-ci.
AttachedTemplate correspond au chemin de l'éventuelle modèle (template), pas du document.
Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés
Le savoir est la seule matière qui s'accroit quand on la partage (Socrate)