KIPRE74
Messages postés120Date d'inscriptionjeudi 15 mai 2008StatutMembreDernière intervention21 novembre 2013
-
21 juil. 2008 à 10:26
youpiyoyo
Messages postés539Date d'inscriptionvendredi 6 juin 2003StatutMembreDernière intervention14 juillet 2010
-
21 juil. 2008 à 14:28
Bonjour à vous,
J'aimerais créer un bouton qui me permette d'ouvrir une feuille excel. en VS 2005;
on m'a proposé ce code mais ça na marche pas.
Merci
Je suis débutant en VB
Option
Explicit
OnOption
Strict
OnImports
Microsoft.Office.Interop.Excel
Imports
System
Imports
System.ComponentModel
Imports
System.Drawing
Imports
System.Runtime.InteropServices
Imports
System.Text
Imports
System.Windows.Forms
Public
Class FormMain
Private
Sub OuvrirFichier()
'Déclaration des variables
Dim xlsapp
As Excel.Application
'Application Excel
Dim book
As Excel.Workbook
'Classeur Excel
Try
'Nouvelle appliation excellxlsapp New Excel.Applicationbook xlsapp.Workbooks.Open(
"chemin du fichier")
Catch ex
As COMExceptionMessageBox.Show(ex.ToString())
End
Try
End
Sub
'Ouvrir le fichier après click sur Le menu.
Private
Sub Men_Ouvrir_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Men_Ouvrir.ClickOuvrirFichier()
End
Sub
'Quitter l'application avec le menu.
Private
Sub Men_Quitter_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Men_Quitter.Click
youpiyoyo
Messages postés539Date d'inscriptionvendredi 6 juin 2003StatutMembreDernière intervention14 juillet 2010 21 juil. 2008 à 10:49
si tu veux juste l'ouvrir et pas le piloter, tu peux faire ca:
Diagnostics.Process.Start("chemin fichier.xls")
sinon ce code devrait fonctionner regarde si tu as bien mis excel en réference...
et essaye xlsapp.Visible = True
ce code fonctionne:
Dim xlsapp As New Excel.Application
xlsapp.Visible = True
Dim book As Excel.Workbook = xlsapp.Workbooks.Open("c:\chemin\test.xls")
youpi :)
KIPRE74
Messages postés120Date d'inscriptionjeudi 15 mai 2008StatutMembreDernière intervention21 novembre 2013 21 juil. 2008 à 11:48
Désolé, ça ne marche toujours pas !
Je suis néophyte en VS et j'ai un peu de mal à te suivre.
Voici mon code où se trouve donc le Problème ? les erreurs sont soulignées
Merci
Option
Explicit
OnOption
Strict
OnImports
Microsoft.Office.Interop.Excel
Imports
System.IO
Imports
System.ComponentModel
Imports
System.Drawing
Imports
System.Runtime.InteropServices
Imports
System.Text
Imports
System.Windows.Forms
Public
Class FormMain
Private
Sub OuvrirFichier()
'Déclaration des variables
Dim xlsapp
AsExcel.Application
'Application Excel
Dim book
AsExcel.Workbook 'Classeur Excel
Try
'Nouvelle appliation excellxlsapp New Excel.Applicationbook xlsapp.Workbooks.Open(
"chemin du fichier")
Catch ex
As COMExceptionMessageBox.Show(ex.ToString())
End
Try
End
Sub
'Ouvrir le fichier après click sur Le menu.
Private
Sub Men_Ouvrir_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Men_Ouvrir.ClickOuvrirFichier()
End
Sub
'Quitter l'application avec le menu.
Private
Sub Men_Quitter_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Men_Quitter.Click
Me.Close()
End
SubEnd
Class
Vous n’avez pas trouvé la réponse que vous recherchez ?
youpiyoyo
Messages postés539Date d'inscriptionvendredi 6 juin 2003StatutMembreDernière intervention14 juillet 2010 21 juil. 2008 à 12:30
oui j'avais bien vu ton code... mais quand tu mets: "Dim xlsapp As Excel.Application 'Application Excel" il faut lui dire vers quoi pointe Excel donc Imports Excel=Microsoft.Office.Interop.Excel
et ensuite que tu verifs tes réferences dans visual studio: donc dans solution explorer: click droit sur ta solution->properties->onglet de gauche references->Add...->COM->Microsoft Excel 11.0...
Si tu ne sais pas comment rajouter une réference à ton projet regarde sur google.
Mais le code que je t'ai fournis plus haut marche..
@+