mdeg
Messages postés28Date d'inscriptionmercredi 31 mars 2010StatutMembreDernière intervention29 avril 2010
-
28 avril 2010 à 15:36
mdeg
Messages postés28Date d'inscriptionmercredi 31 mars 2010StatutMembreDernière intervention29 avril 2010
-
29 avril 2010 à 16:39
Bonjour,
J'ai écrit un code pour écrire dans un fichier texte à l'aide d'un commondialog.
l'utilisateur choisi l'endroit où il veut enregistrer le fichier, ainsi que ne nom du fichier.
Voici un extrait du code :
With CommonDialog1
.DialogTitle = "selectionner un fichier" 'titre de la boite
.Filename = "*.txt" 'on recherche un fichier d'extension txt
.CancelError = False 'pour ne pas partir en erreur si on click sur annuler
.FilterIndex = 2
.flags = cdlOFNCreatePrompt And cdlOFNFileMustExist And cdlOFNOverwritePrompt
.ShowSave
End With
On Error GoTo Ecrire
If FileLen(CommonDialog1.Filename) >= 0 Then
reponse = MsgBox("Le fichier " & UserForm_Helmert.CommonDialog1.Filename & " existe déja. Voulez-vous l'écraser?", vbYesNoCancel, "Nom de fichier déja existant")
If reponse = vbNo Then
CommonDialog1.ShowSave
End If
If reponse = vbCancel Then
Exit Sub
End If
If reponse = vbYes Then
GoTo Ecrire
End If
End If
Ecrire:
Open CommonDialog1.Filename For Output As #5
Print #5, "Transformation de Helmert"
Print #5,
Print #5, "Fichier de points homologues : " & UserForm_Accueil.CommonDialog1.Filename
Print #5, "Fichier de résultats : " & UserForm_Helmert.CommonDialog1.Filename
Print #5,
Close #5
Lorsque l'écriture est terminée je voudrais ouvrir le fichier texte dans le wordpad par exemple. Quelle est la fonction à utliser?
cs_Le Pivert
Messages postés7903Date d'inscriptionjeudi 13 septembre 2007StatutContributeurDernière intervention11 mars 2024137 29 avril 2010 à 11:05
Je viens de faire le test avec un nouveau classeur Excel et cela fonctionne. Je remet donc le code tel quel:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub CommandButton1_Click()
ouvrirfichier
End Sub
Sub ouvrirfichier()
Dim Ret As Variant
Ret = ShellExecute(hwnd, "open", "C:\Documents and Settings\Propriétaire\Mes documents\My eBooks\Doc à conserver\AccuseReception-9108018363120.pdf", "", vbNullString, 1)
End Sub
cs_Le Pivert
Messages postés7903Date d'inscriptionjeudi 13 septembre 2007StatutContributeurDernière intervention11 mars 2024137 28 avril 2010 à 16:28
Bonjour,
'Ouvrir fichiers dans leur programme par défaut
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Sub ouvrirfichier()
Dim Ret As Variant
Ret = ShellExecute(hwnd, "open", ?Chemin du fichier?, "", vbNullString, 1)
End Sub
@+
cs_Le Pivert
Messages postés7903Date d'inscriptionjeudi 13 septembre 2007StatutContributeurDernière intervention11 mars 2024137 28 avril 2010 à 16:30
Erreur de guillemets dans le chemin du fichier
'Ouvrir fichiers dans leur programme par défaut
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Sub ouvrirfichier()
Dim Ret As Variant
Ret = ShellExecute(hwnd, "open", "Chemin du fichier?, "", vbNullString, 1)
End Sub
mdeg
Messages postés28Date d'inscriptionmercredi 31 mars 2010StatutMembreDernière intervention29 avril 2010 29 avril 2010 à 08:47
Bonjour,
J'ai essayé le code que tu as écrit, mais dans la fonction il me met une erreur quand j'écris lib et alias. Donc ça ne fonctionne pas... Tu sais pourquoi?