selectionner un fichier sur un autre disque en vba

  • Initiateur de la discussion Initiateur de la discussion bpol
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

bpol

XLDnaute Impliqué
bonjour,

j'ai une macro qui comporte cette partie

'and
Sheets("récap").Select
Ligne = Range("A65536").End(xlUp).Row + 1
Cells(Ligne, 1) = Sheets("tableau").Range("E1")
Cells(Ligne, 2) = Sheets("tableau").Range("H1")
Cells(Ligne, 3) = Sheets("tableau").Range("G1")
Cells(Ligne, 4) = Sheets("tableau").Range("I1")
'and




Sheets("calcul").Select
Ligne = Range("A65536").End(xlUp).Row + 1
Cells(Ligne, 1) = Sheets("tableau").Range("E1")
Cells(Ligne, 2) = Sheets("tableau").Range("H1")
Cells(Ligne, 3) = Sheets("tableau").Range("G1")
Cells(Ligne, 4) = Sheets("tableau").Range("I1")
'and

Worksheets("tableau").Select
'And
ActiveWorkbook.save

End Sub

mais je voudrais que la 2e partie de l'enregistrement se fasse sur un autre fichier mais qui n'est pas sur le même disque( d'ailleurs plus tard il sera sur un autre pc relié en réseau)
'and
Sheets("récap").Select
Ligne = Range("A65536").End(xlUp).Row + 1
Cells(Ligne, 1) = Sheets("tableau").Range("E1")
Cells(Ligne, 2) = Sheets("tableau").Range("H1")
Cells(Ligne, 3) = Sheets("tableau").Range("G1")
Cells(Ligne, 4) = Sheets("tableau").Range("I1")
'and


Workbooks("c:\temps.xls").Sheets ("temps").Select


Ligne = Range("A65536").End(xlUp).Row + 1
Cells(Ligne, 1) = Sheets("tableau").Range("E1")
Cells(Ligne, 2) = Sheets("tableau").Range("H1")
Cells(Ligne, 3) = Sheets("tableau").Range("G1")
Cells(Ligne, 4) = Sheets("tableau").Range("I1")
'and

Worksheets("tableau").Select
'And
ActiveWorkbook.save

End Sub


merci du coup de main


Bpol
 
Re : selectionner un fichier sur un autre disque en vba

re,

j'ai modifié comme cela mais toujours le bug

Dim WB1 As Workbook
Dim WB2 As Workbook
Dim lig As Long
Dim choixLig As Long
Dim col As Long
Dim choixCol As Long
Dim Ligne As Long

Set WB1 = ActiveWorkbook
Sheets("tableau").Activate '????? est-ce bien cette feuille ?????
' Trouver la ligne
choixLig = 0

For lig = 7 To 256
If Range("E7") = 0 Then choixLig = 7: Exit For

If Range("E" & lig) = Range("E1") Then choixLig = lig: Exit For

If Range("E" & lig) = 0 And Range("F3") > 1 Then
lig = Range("E65536").End(xlUp).Row + 1
Cells(lig, 5) = Range("E1")
choixLig = lig: Exit For
End If
Next lig

Cells(choixLig, 5) = Range("E1")

' If choixLig = 0 Then
' MsgBox "L'enregistrement n'est pas possible", vbCritical + vbOKOnly, "Erreur"
' Exit Sub
' End If

' Trouver la colonne
choixCol = 0
For col = 6 To 9
If Cells(choixLig, col) = 0 Then
choixCol = col
Exit For
End If
Next col

If choixCol = 0 Then
MsgBox "L'enregistrement n'est pas possible", vbCritical + vbOKOnly, "Erreur"
Exit Sub
End If

' Afficher le résultat
Cells(choixLig, choixCol).Value = Range("I1").Value

'and
Sheets("récap").Select
Ligne = Range("A65536").End(xlUp).Row + 1
Cells(Ligne, 1) = Sheets("tableau").Range("E1")
Cells(Ligne, 2) = Sheets("tableau").Range("H1")
Cells(Ligne, 3) = Sheets("tableau").Range("G1")
Cells(Ligne, 4) = Sheets("tableau").Range("I1")
'and
Windows("C\temps.xls").Activate
Set WB2 = ActiveWorkbook
Ligne = Range("A65536").End(xlUp).Row + 1
Cells(Ligne, 1) = WB1.Sheets("tableau").Range("E1")
Cells(Ligne, 2) = WB1.Sheets("tableau").Range("i1")
Cells(Ligne, 3) = WB1.Sheets("tableau").Range("h1")
Cells(Ligne, 4) = WB1.Sheets("tableau").Range("g1")
'and
Windows("TRC mmss.xls").Activate
Worksheets("tableau").Select
'And
WB1.Save
WB2.Save
 
Re : selectionner un fichier sur un autre disque en vba

Bonjour

si tu es dans la feuille contenant les valeurs à copier (E1,H1...)
le classeur "client" (destination) sur un autre lecteur est actuellement fermé. Testé sur disque dur externe (H)
à adapter à tes paramètres (nom des feuilles, classeurs etc.)
la technique de l'array (tablo) est 20 fois plus rapide que l'égalité de celllues

Code:
Dim tablo
'.....
ReDim tablo(3)
With Sheets(1)
    tablo(0) = .Range("E1")
    tablo(1) = .Range("H1")
    tablo(2) = .Range("G1")
    tablo(3) = .Range("I1")
End With

ChDir "H:\essai"
   Workbooks.Open Filename:="H:\essai\client.xls"
Ligne = Range("A65536").End(xlUp).Row + 1
Range(Cells(Ligne, 1), Cells(Ligne, 4)) = tablo
With activeworkbook
    .Save
    .Close
End With
 
Dernière édition:
Re : selectionner un fichier sur un autre disque en vba

c'est un extrait de macro
tu l'insères dans ta procédure

J'ai essayé chez moi: ca fonctionne (avant de proposer, je teste toujours une maquette)

comme tu dis pas où quand comment quel message, je ne peux rien faire pour toi...
désolé, bon WE
 
Re : selectionner un fichier sur un autre disque en vba

RE Michel,

voici mon fichier: http://cjoint.com/?guty0MR5ct

et la macro a modifier

Private Sub cmdEnregistrer_Click()
Dim lig As Long
Dim choixLig As Long
Dim col As Long
Dim choixCol As Long

' Trouver la ligne
choixLig = 0

For lig = 7 To 256
If Range("E7") = 0 Then choixLig = 7: Exit For

If Range("E" & lig) = Range("E1") Then choixLig = lig: Exit For

If Range("E" & lig) = 0 And Range("F3") > 1 Then
lig = Range("E65536").End(xlUp).Row + 1
Cells(lig, 5) = Range("E1")
choixLig = lig: Exit For
End If
Next lig

Cells(choixLig, 5) = Range("E1")

' If choixLig = 0 Then
' MsgBox "L'enregistrement n'est pas possible", vbCritical + vbOKOnly, "Erreur"
' Exit Sub
' End If

' Trouver la colonne
choixCol = 0
For col = 6 To 9
If Cells(choixLig, col) = 0 Then
choixCol = col
Exit For
End If
Next col

If choixCol = 0 Then
MsgBox "L'enregistrement n'est pas possible", vbCritical + vbOKOnly, "Erreur"
Exit Sub
End If

' Afficher le résultat
Cells(choixLig, choixCol).Value = Range("I1").Value

'and
Sheets("récap").Select
Ligne = Range("A65536").End(xlUp).Row + 1
Cells(Ligne, 1) = Sheets("tableau").Range("E1")
Cells(Ligne, 2) = Sheets("tableau").Range("H1")
Cells(Ligne, 3) = Sheets("tableau").Range("G1")
Cells(Ligne, 4) = Sheets("tableau").Range("I1")
'and

ce que je désire c'est qu'au lieu de copier les cellules sur la feuille calcul c'est de les copier dans un autre fichier sur un autre disque dur
'and
Sheets("calcul").Select
Ligne = Range("A65536").End(xlUp).Row + 1
Cells(Ligne, 1) = Sheets("tableau").Range("E1")
Cells(Ligne, 2) = Sheets("tableau").Range("H1")
Cells(Ligne, 3) = Sheets("tableau").Range("G1")
Cells(Ligne, 4) = Sheets("tableau").Range("I1")
'and

Worksheets("tableau").Select
'And
ActiveWorkbook.save

End Sub

Bon WE

Bpol
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
1
Affichages
180
  • Question Question
Microsoft 365 worksheet_change
Réponses
29
Affichages
479
Réponses
3
Affichages
194
Réponses
4
Affichages
179
Réponses
10
Affichages
547
Retour