problème automatisation

imanou

XLDnaute Nouveau
bonjour,

j'ai un problème dans mon code pour automatiser une gestion/transformation de fichier.
le problème est que le fichier s'enregistre à l'emplacement voulu mais pas avec le nom que je lui ai donné, et par la suite je n'arrive pas à utiliser ce fichier copié et renommé

je joint le fichier contenant ma macro

est ce que quelqu'un à une idée sur comment résoudre cela

Merci d'avance.
 

Pièces jointes

  • zipTestMacro.zip
    17.4 KB · Affichages: 21

kjin

XLDnaute Barbatruc
Re : problème automatisation

Bonsoir,
Code:
sDate = Cells(13, 3)
For i = 21 To 41
    If Cells(4, 3).Value = Cells(i, 1).Value Then
        Set wb = Workbooks.Open(chemin01 & "\" & Cells(i, 4).Value & "\" & Cells(10, 3).Value & ".xls")
        f = chemin00 & "\" & Cells(i, 3) & "_DataRESULT" & sDate & ".xls"
        wb.SaveCopyAs f
        wb.Close SaveChanges:=False
        Workbooks.Open f
    End If
Next
maintenant, si c'est pour réouvrir le fichier une fois refermé autant le laisser ouvert et le renomer
Code:
sDate = Cells(13, 3)
For i = 21 To 41
    If Cells(4, 3).Value = Cells(i, 1).Value Then
        Set wb = Workbooks.Open(chemin01 & "\" & Cells(i, 4).Value & "\" & Cells(10, 3).Value & ".xls")
        f = chemin00 & "\" & Cells(i, 3) & "_DataRESULT" & sDate & ".xls"
        wb.SaveAs f
    End If
Next
A+
kjin
 

imanou

XLDnaute Nouveau
Re : problème automatisation

Bonsoir,
Code:
sDate = Cells(13, 3)
For i = 21 To 41
    If Cells(4, 3).Value = Cells(i, 1).Value Then
        Set wb = Workbooks.Open(chemin01 & "\" & Cells(i, 4).Value & "\" & Cells(10, 3).Value & ".xls")
        f = chemin00 & "\" & Cells(i, 3) & "_DataRESULT" & sDate & ".xls"
        wb.SaveCopyAs f
        wb.Close SaveChanges:=False
        Workbooks.Open f
    End If
Next
maintenant, si c'est pour réouvrir le fichier une fois refermé autant le laisser ouvert et le renomer
Code:
sDate = Cells(13, 3)
For i = 21 To 41
    If Cells(4, 3).Value = Cells(i, 1).Value Then
        Set wb = Workbooks.Open(chemin01 & "\" & Cells(i, 4).Value & "\" & Cells(10, 3).Value & ".xls")
        f = chemin00 & "\" & Cells(i, 3) & "_DataRESULT" & sDate & ".xls"
        wb.SaveAs f
    End If
Next
A+
kjin

bonjour,
le problème persiste et j'ai toujours le runtime error 1004, le fichier s'ouvre comme meme, mais le nom n'est pas correct le cells(i,3).value n''apparait pas (_DataRESULT20100927.XLS),
le problème se situe au niveau du cells(i,3)
 

kjin

XLDnaute Barbatruc
Re : problème automatisation

Bonjour,
Effectivement j'ai omis d'inverser les 2 lignes bleues
J'ai ajouté les variables intermédiaires qui permettent d'y voir plus clair
Code:
Sub new_file()
Dim sDate$, sFichier$, sChoix$
Dim i%
chemin00 = "C:\Users\...\Desktop\la macro\07. Informations DOCS"
chemin01 = "C:\Users\...\la macro\03. FICHIER SORTIE"
sDate = Cells(13, 3)
sFichier = Cells(10, 3)
sChoix = Cells(4, 3)
For i = 21 To 41
    If sChoix = Cells(i, 1) Then
        [COLOR="Blue"]pFichier = chemin00 & "\" & Cells(i, 3) & "_DataRESULT" & sDate & ".xls"[/COLOR]
        [COLOR="Blue"]Set wb = Workbooks.Open(chemin01 & "\" & Cells(i, 4) & "\" & sFichier & ".xls")[/COLOR]
        wb.SaveAs pFichier
    End If
Next

End Sub
A+
kjin
 

Statistiques des forums

Discussions
312 523
Messages
2 089 309
Membres
104 119
dernier inscrit
karbone57