Bonjour
J'ai besoin apres rafraichissement de mon fichier .rep, d'exporter tout les reports vers Excel en automatique.
j'ai trouvé sur le net 2 possibilités :
la premiere exporte seulement le report actif.
Sub export()
ActiveReport.ExportAsExcel ("D:\Documents and Settings\Toto\Desktop\fichier.xls")
End Sub
la deuxieme permet d'exporter tous les reports mais j'ai un message d'ereur "70 - permission refusée"
' ---------------------------------------------------------------
' principe : exportation des différents rapports au format texte,
' puis importation dans des feuilles excel.
' ---------------------------------------------------------------
Sub export_Excel()
On Error GoTo error_handler
Dim Doc As Document
Dim Rep As Report
Dim i As Integer
Dim ExcelDoc As String ' nom du fichier excel cible
Dim Path As String ' lien pour le fichier excel cible
ExcelDoc = ActiveDocument.Name & lparam ' nom du ficher excel
Path = "D:\Documents and Settings\galloroc\Desktop" ' lien pour stocker le fichier excel
' enregistre les rapports au format text
Set Doc = ActiveDocument
For i = 1 To Doc.Reports.Count
Set Rep = Doc.Reports.item(i)
If Dir(Path & Rep.Name & ".txt") <> " " Then
Kill Path & Rep.Name & ".txt"
End If
Rep.ExportAsText (Path & Rep.Name & ".txt")
Next i
Set vbExcel = CreateObject("Excel.Application")
With vbExcel
' création d'un fichier excel, qui contiendra les ficher au format txt
If Dir(Path & ExcelDoc & ".xls") <> " " Then
Kill Path & ExcelDoc & ".xls"
End If
.Workbooks.Add
.ActiveWorkbook.SaveAs Path & ExcelDoc & ".xls"
' ouvre les sources, enregistre au formazt excel, et immport dans la bonne destination
For i = 1 To Doc.Reports.Count
Set Rep = Doc.Reports.item(i)
.Workbooks.Open Path & Rep.Name & ".txt"
If Dir(Path & Rep.Name & ".xls") <> " " Then
Kill Path & Rep.Name & ".xls"
End If
.ActiveWorkbook.SaveAs Path & Rep.Name & ".xls"
' copie des feuilles dans le fichier excel
.Workbooks(Rep.Name & ".xls").Sheets(Rep.Name).Move _
Before:=.Workbooks(ExcelDoc & ".xls").Sheets("feuil1")
Next i
' ferme tout les workbooks
.ActiveWorkbook.Save
Workbooks.Close
' ferme l'application
.Quit
End With
' libère la mémoire
Set vbExcel = Nothing
Exit Sub
error_handler:
If Err.Number = 53 Then Resume Next
MsgBox Err.Number & " - " & Err.Description
Workbooks.Close
vbExcel.Quit
Set vbExcel = Nothing
Set OlkApp = Nothing
End Sub
Pourriez-vous m'aider ? Par avance merci.





Répondre avec citation


Pensez à consulter les 


Partager