Intégré un bouton dans excel par VB6

Résolu
cs_petchy Messages postés 710 Date d'inscription jeudi 20 février 2003 Statut Membre Dernière intervention 19 mai 2015 - 15 avril 2006 à 17:08
cs_petchy Messages postés 710 Date d'inscription jeudi 20 février 2003 Statut Membre Dernière intervention 19 mai 2015 - 16 avril 2006 à 08:18
bonjour
[VB6]
A l'aide d'un bouton dans une forme je lance un fichier Excel.Comment à l'ouverture de se fichier lui intégré un bouton et lorsqu'on click sur se bouton on déclencherait une macro .
merci
@ plus
petchy

2 réponses

michelxld Messages postés 402 Date d'inscription vendredi 6 août 2004 Statut Membre Dernière intervention 12 octobre 2008 32
15 avril 2006 à 19:36
bonsoir Petchy

j'espere que cet exemple pourra t'aider

Private Sub Command1_Click()
Dim ExcelApp As Excel.Application
Dim Wb As Excel.Workbook
Dim Obj As Excel.OLEObject
Dim laMacro As String
Dim x As Integer


Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Visible = True
Set Wb = ExcelApp.Workbooks.Add(1)



Set Obj = Wb.Worksheets(1).OLEObjects.Add("Forms.CommandButton.1")
With Obj
.Left = 50
.Top = 50
.Width = 120
.Height = 30
.Object.Caption = "Supprimer données feuille"
End With


laMacro = "Sub CommandButton1_Click()" & vbCrLf
laMacro = laMacro & "Cells.Clear" & vbCrLf
laMacro = laMacro & "End Sub"


With Wb.VBProject.VBComponents(ActiveSheet.Name).CodeModule
x = .CountOfLines + 1
.InsertLines x, laMacro
End With


End Sub

bonne soiree
michel
3
cs_petchy Messages postés 710 Date d'inscription jeudi 20 février 2003 Statut Membre Dernière intervention 19 mai 2015 4
16 avril 2006 à 08:18
salut Michel
merci pour se code
petchy
0
Rejoignez-nous