Utilisation de commondialog.showsave

yangoal25 Messages postés 51 Date d'inscription mardi 22 novembre 2005 Statut Membre Dernière intervention 30 juin 2008 - 19 mai 2006 à 14:48
yangoal25 Messages postés 51 Date d'inscription mardi 22 novembre 2005 Statut Membre Dernière intervention 30 juin 2008 - 19 mai 2006 à 15:08
Bonjour,

J'exporte les données de mon datagrid vers excel. Mais dans mon code je suis obligé de mettre "en dur" la destination du fichier qui doit déjà exister.

Le problème, comme vous l'avez deviné, est que j'aimerais qu'il demande à l'utilisateur ou ilveut exporter ces données et les sauvegarder dans un fichier excel qu'il crééra à ce moment là.

J'essaie de trouver une solution avec commondialog1.showsave, mais cela ne créé pas de nouveau fichier excel.

Voici mon code pour mettre les données vers excel (qui fonctionne si le fichier existe)

Private Sub Command2_Click()
Dim sheet As Object
Dim exldoc As Object
Dim exlapp As Object
Dim i As Integer
Dim j As Integer
Dim z As Integer
Dim adresse As String

CommonDialog1.ShowSave
adresse = CommonDialog1.FileName
'adresse = "C:\TFE\test.xls"
Set exlapp = CreateObject("excel.application")
Set exldoc = exlapp.Workbooks.Open(adresse)
Set sheet = exlapp.ActiveWorkbook.ActiveSheet
exlapp.Visible = True




Select Case varIndex
Case 1
   i = 0
   DataEnvironment7.Command2 CDateDemande
   If i = 0 Then
      Do Until DataEnvironment7.rsCommand2.EOF = True
         For z = 0 To DataEnvironment7.rsCommand2.Fields.Count - 1
            sheet.Cells(i + 1, z + 1).Value = DataEnvironment7.rsCommand2.Fields(z).Name
         Next z
         DataEnvironment7.rsCommand2.MoveNext
      Loop
      i = i + 1
   End If
  
   If i > 0 Then
      DataEnvironment7.rsCommand2.MoveFirst
      Do Until DataEnvironment7.rsCommand2.EOF = True
         For z = 0 To DataEnvironment7.rsCommand2.Fields.Count - 1
            sheet.Cells(i + 1, z + 1).Value = DataEnvironment7.rsCommand2.Fields(z).Value
         Next z
      DataEnvironment7.rsCommand2.MoveNext
      i = i + 1
      Loop
   End If
  
   Set exlapp = Nothing
   DataEnvironment7.rsCommand2.Close

case ...

2 réponses

cs_Le routier Messages postés 16 Date d'inscription lundi 20 février 2006 Statut Membre Dernière intervention 19 mai 2006
19 mai 2006 à 14:56
Essaye Application.GetSaveAsFilename("ICI PROPOSE UN NOM DE FICHIER")




 



Préviens moi si ça marche






Les routiers sont sympas !!!
0
yangoal25 Messages postés 51 Date d'inscription mardi 22 novembre 2005 Statut Membre Dernière intervention 30 juin 2008
19 mai 2006 à 15:08
Ou dois-je mettre ce code?

Remplace-t-il quelque chose où l'ajouter?

le showsave m'affiche une boite et l'application.getsaveasfilename m'affiche une nouvelle boite de dialogue
0
Rejoignez-nous