VB et Excel

julien76330 Messages postés 1 Date d'inscription lundi 27 février 2006 Statut Membre Dernière intervention 6 mars 2006 - 6 mars 2006 à 09:58
jpleroisse Messages postés 1788 Date d'inscription mardi 7 novembre 2000 Statut Membre Dernière intervention 11 mars 2006 - 6 mars 2006 à 13:54
bonjour, j'ai un petit souci :
Il faudrai que j'ouvre un fichier Excel (que je choisi avec un exploreur pour ensuite recopier la première colonne dans mon programme en Vb dans une suite de Text1(i)
j'ai déjà réalisé la selection du fichier. Si qq1 pouvait m'éclairer

Julien VB-OPC, [mailto:fandejulien@msn.com mailto:fandejulien@msn.com]

1 réponse

jpleroisse Messages postés 1788 Date d'inscription mardi 7 novembre 2000 Statut Membre Dernière intervention 11 mars 2006 27
6 mars 2006 à 13:54
Bonjour,
N'oublie pas de cocher la référence à Excel.

Option Explicit

Private Sub Form_Load()
Dim xlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
If Not IsObject(xlApp) Then
MsgBox "Vous avez besoin de Microsoft Excel Pour cette fonction", _
vbExclamation, "Excel"
Exit Sub
End If
With CommonDialog1
.DialogTitle = "rechercher un fichier"
.CancelError = True
.InitDir = "C:\Mes documents"
.Filter = "Fichier Excel (*.xls)|*.xls"
On Error GoTo Annuler
.ShowOpen
End With
Set xlBook = xlApp.Workbooks.Open(CommonDialog1.FileName)
Set xlSheet = xlApp.ActiveSheet
Text1(0) = xlSheet.Cells(1, 1)
Text1(1) = xlSheet.Cells(2, 1)
'etc....
GoTo Suite
xlBook.Close
xlApp.Quit
Set xlApp = Nothing
Annuler: MsgBox "Vous n'avez sélectionneé aucun fichier", vbInformation, "Annuler"
Suite:

End Sub

jpleroisse

Si une réponse vous convient, cliquez Réponse Acceptée.
0
Rejoignez-nous