[BO] Pb : Exportation des plusieurs rapports au format Excel

Pb : Exportation des plusieurs rapports au format Excel [BO] - VB/VBA/VBS - Programmation

Marsh Posté le 20-04-2004 à 10:11:26    

bonjour,
 
je souhaiterais exporter tout les rapports d'un document BO dans un fichier excel.
qui contient donc autant de feuilles Excel, que de rapport Bo dans le document BO.
 
OK ?
 
principe :
- j'exporte chaque rapport BO dans un fichier texte.
- je crée un fichier Excel
- j'importe les fichiers texte dans les feuilles Excel.
- j'enregistre
 - je ferme, je libère tout (mémoire...)
 
voici un code que j'ai trouvé sur des forums anglais. :
 

Code :
  1. ' ---------------------------------------------------------------
  2. ' exportation au format xls
  3. ' ---------------------------------------------------------------
  4. ' principe : exportation des différents rapports au format texte,
  5. '            puis importation dans des feuilles excel.
  6. ' ---------------------------------------------------------------
  7. Sub export_Excel(lparam As String)
  8. On Error GoTo error_handler
  9. Dim Doc As Document
  10. Dim Rep As Report
  11. Dim i As Integer
  12. Dim ExcelDoc As String ' nom du fichier excel cible
  13. Dim Path As String ' lien pour le fichier excel cible
  14. ExcelDoc = ActiveDocument.Name & lparam ' nom du ficher excel
  15. Path = "P:\test\"  ' lien pour stocker le fichier excel
  16. ' enregistre les rapports au format text
  17. Set Doc = ActiveDocument
  18. For i = 1 To Doc.Reports.Count
  19.   Set Rep = Doc.Reports.Item(i)
  20. If Dir(Path & Rep.Name & ".txt" ) <> " " Then
  21.     Kill Path & Rep.Name & ".txt"
  22.   End If
  23.   Rep.ExportAsText (Path & Rep.Name & ".txt" )
  24. Next i
  25. Set vbExcel = CreateObject("Excel.Application" )
  26. With vbExcel
  27. ' création d'un fichier excel, qui contiendra les ficher au format txt
  28.   If Dir(Path & ExcelDoc & ".xls" ) <> " " Then
  29.     Kill Path & ExcelDoc & ".xls"
  30.   End If
  31.   .Workbooks.Add
  32.   .ActiveWorkbook.SaveAs Path & ExcelDoc & ".xls"
  33. ' ouvre les sources, enregistre au formazt excel, et immport dans la bonne destination
  34. For i = 1 To Doc.Reports.Count
  35.   Set Rep = Doc.Reports.Item(i)
  36.   .Workbooks.Open Path & Rep.Name & ".txt"
  37.   If Dir(Path & Rep.Name & ".xls" ) <> " " Then
  38.     Kill Path & Rep.Name & ".xls"
  39.   End If
  40.   .ActiveWorkbook.SaveAs Path & Rep.Name & ".xls"
  41.   ' copie des feuilles dans le fichier excel
  42.     .Workbooks(Rep.Name & ".xls" ).Sheets(Rep.Name).Move _
  43.       Before:=.Workbooks(ExcelDoc & ".xls" ).Sheets("Sheet1" )
  44. Next i
  45. ' ferme tout les workbooks
  46.   .ActiveWorkbook.Save
  47.   Workbooks.Close
  48. ' ferme l'application
  49.   .Quit
  50. End With
  51.   ' libère la mémoire
  52.   Set vbExcel = Nothing
  53. Exit Sub
  54. error_handler:
  55. If Err.Number = 53 Then Resume Next
  56.   MsgBox Err.Number & " - " & Err.Description
  57.   Workbooks.Close
  58.   vbExcel.Quit
  59.   Set vbExcel = Nothing
  60.     Set OlkApp = Nothing
  61. End Sub


 
problème, marche pas, il me dit une erreur :
70 - permission refusée.
 
une idée ??? perso, je ne vois pas, si ce n'est que Workbooks devrais peut etreetre en français (j'ai déjà eu des Pb avec des nom de méthode en anglais, qui devais etre en français...)
 
mais je ne trouve pas de traduction qui marche pour Workbooks...
 
des idées...
 
merci d'avance.
bonne journée.

Reply

Marsh Posté le 20-04-2004 à 10:11:26   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed