Ouvrir un fichier a l'aide bouton vb

Résolu/Fermé
DERAZ - 28 févr. 2012 à 19:39
 derch - 1 mars 2012 à 00:22
Bonjour,
j'ai un travail sur un fichier excel ,je veux l'ouvrir a laide d'un bouton en vb6 .je cherche un code mais j'ai pas trouver.

A voir également:

1 réponse

Lord Zero Messages postés 459 Date d'inscription lundi 18 octobre 2010 Statut Membre Dernière intervention 15 juin 2018 115
Modifié par Lord Zero le 29/02/2012 à 09:51
Private Sub Command1_Click() 
'Déclaration des variables 
 Dim appExcel As Excel.Application 'Application Excel 
 Dim wbExcel As Excel.Workbook 'Classeur Excel 
 Dim wsExcel As Excel.Worksheet 'Feuille Excel 
  
'Ouverture de l'application 
 Set appExcel = CreateObject("Excel.Application") 
 'Ouverture d'un fichier Excel 
 Set wbExcel = appExcel.Workbooks.Open("chemin+fichier.xls") 
'wsExcel correspond à la première feuille du fichier 
 Set wsExcel = wbExcel.Worksheets(1) 
 appExcel.Visible = True 

End Sub


Ne pas oublier de cocher la librairie excel dans Projet/Références/Microsoft Excel...

@+

Développeur VB6, VBS, VBA, VB.NET, C#, HTML, PHP, JAVASCRIPT, SQL.
0
merci bcp ,mais le petit problème c'est que en excel 2007 il faut ajouter un x
par exemple/open("D:\monprojet\classeur1.xlsx")
monprojet c'est lefichier ou se trouve classeur1

JE VOUS PROPOSE UN AUTRE CODE QUE JE VOIX UN PEUT PLUS COURT
(General)
Dim xlTmp As Excel.Application
Private Sub Command1_Click()

Set xlTmp = Excel.Application
xlTmp.Workbooks.Open ("d:\nom du fichier contenant le classeur\Classeur1.xlsx")
xlTmp.Visible = True
End Sub
0