VB.NET change Excel form elements

rdg_dawg
07-08-2004, 12:41 PM
I am having a problem with trying to find a way to change the (text/caption) property of a button I created in Excel within my code. Imports Microsoft.Office.Core

Public Class Form1
Inherits System.Windows.Forms.Form

Dim thisApplication As New Excel.Application

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click

Dim wb As Excel.Workbook = thisApplication.Workbooks.Open("C:\training.xls")
Dim sh As Excel.Worksheet
Dim myPicture As Excel.Shapes

'insert the picture
sh.Shapes.AddPicture("C:\Documents and Settings\RGoudelock\My Documents\My Pictures\UCB.gif", _
Office.MsoTriState.msoTrue, Office.MsoTriState.msoTrue, 0, 0, 120, 40)
sh.Shapes.AddFormControl(Excel.XlFormControl.xlButtonControl, 0, 50, 100, 30)

'Save all the workbooks in the application
For Each wb In thisApplication.Workbooks
wb.Save()
Next wb

wb.Close()

thisApplication.Quit()
wb = Nothing
sh = Nothing

GC.Collect()

End Sub

herilane
07-08-2004, 01:02 PM
Hello and welcome :)

Try this:
Dim btn As Excel.Shape
btn = sh.Shapes.AddFormControl(Excel.XlFormControl.xlButtonControl, 0, 50, 100, 30)
btn.TextFrame.Characters.Text = "aha"

rdg_dawg
07-08-2004, 01:32 PM
Thanks a million!!!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum