LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 296
Default Adding a Control programatically

Thanks Patrick,

If I wanted say a ListBox (with pre-determined values), instead of a
Button, how would the code alter?



Regards



On Mon, 4 Jul 2005 05:30:02 -0700, "Patrick Molloy"
wrote:

use a "Forms" command button instead of teh ActiveX version
This code adds a button, gives it a caption and assigns th ecode to run


Sub AddFormsButton()
' AddFormsButton
Dim ws As Worksheet
Set ws = ActiveSheet
ws.Buttons.Add(94.5, 11.25, 109.5, 30.75).Select
With Selection
.OnAction = "MyProcedure"
.Characters.Text = "Show a message"
End With
End Sub
Private Sub MyProcedure()
msbox "ok"
End Sub


"Richard Buttrey" wrote:

Hi,

I have some VBA code which opens up a .txt file, hacks the formatting
around a bit deleting superfluous stuff, and leaves the user with a
nice neat database.

I recorded the following code to add a command button to the
worksheet, with the intention of adding some further code behind the
button.

Sub AddButton

ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1", _
Link:=False, DisplayAsIcon:=False, Left:=237.75, Top:=21, Width:=93, _
Height:=22.5).Select
Range("a1").Select

End Sub

When I test this by playing it back in the VBA window, it halts with
the error message "Can't enter break mode at this time", Continue End
Help and the usual Debug button is greyed out.
If I select 'End', the button appears on the worksheet in Edit Mode,
but I can't procede with any more code in the subroutine

First of all can someone tell me what's wrong with the code, and then
secondly, assuming I can succesfully place a button on the worksheet,
how can I add some code programatically to the button object - or
indeed any other control?

Usual TIA




__
Richard Buttrey
Grappenhall, Cheshire, UK
__________________________


__
Richard Buttrey
Grappenhall, Cheshire, UK
__________________________
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to programatically control a 3D-sum? Ake Excel Worksheet Functions 6 February 2nd 06 09:20 AM
Programatically control picture property of Image control Brassman[_5_] Excel Programming 5 May 24th 05 09:32 PM
default references or adding programatically sebastienm Excel Programming 0 August 25th 04 09:31 PM
Changing what is displayed in an image control programatically Eric Kehr Excel Programming 2 April 27th 04 08:16 AM
Adding components to multipage programatically Nigel Brown[_2_] Excel Programming 0 August 4th 03 10:25 AM


All times are GMT +1. The time now is 06:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"